[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wekalist
Subject:    [Wekalist] Error while serializing PrincipalComponents
From:       Tim Lorsbach <lorsbach () envipath ! com>
Date:       2020-05-15 8:00:32
Message-ID: 1e56cfe1-a033-ba17-dc03-9ff05c36c2f9 () envipath ! com
[Download RAW message or body]

Hi,

in one of my current projects I have to store a 
weka.filters.unsupervised.attribute.PrincipalComponents object on disk.

As it implements the Filter interface, which itself implements the 
Serializable interface, the PrincipalComponents object should be 
serializable.

However, it throws a error due to the member "UpperSymmDenseMatrix 
m_Correlation" not being serializable.

This field is only used in within the setup step and can be calculated 
if the setup method is called again.

Attached you'll find a diff file making the member transient and 
recalculate m_Correlation if required.

Best regards,

Tim


["PrincipalComponents.diff" (text/x-patch)]

diff --git a/weka/src/main/java/weka/filters/unsupervised/attribute/PrincipalComponents.java \
b/weka/src/main/java/weka/filters/unsupervised/attribute/PrincipalComponents.java \
                index 743758255..898e55ecc 100644
--- a/weka/src/main/java/weka/filters/unsupervised/attribute/PrincipalComponents.java
+++ b/weka/src/main/java/weka/filters/unsupervised/attribute/PrincipalComponents.java
@@ -116,7 +116,7 @@ public class PrincipalComponents extends Filter implements \
OptionHandler,  protected int m_NumInstances;
 
   /** Correlation matrix for the original data. */
-  protected UpperSymmDenseMatrix m_Correlation;
+  protected transient UpperSymmDenseMatrix m_Correlation;
 
   /**
    * If true, center (rather than standardize) the data and compute PCA from
@@ -730,8 +730,10 @@ public class PrincipalComponents extends Filter implements \
OptionHandler,  m_NumInstances = m_TrainInstances.numInstances();
     m_NumAttribs = m_TrainInstances.numAttributes();
 
-    // fillCorrelation();
-    fillCovariance();
+    if (m_Correlation == null) {
+      // fillCorrelation();
+      fillCovariance();
+    }
 
     // get eigen vectors/values
 



_______________________________________________
Wekalist mailing list -- wekalist@list.waikato.ac.nz
Send posts to wekalist@list.waikato.ac.nz
To unsubscribe send an email to wekalist-leave@list.waikato.ac.nz
To subscribe, unsubscribe, etc., visit \
https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz List \
etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic