GithubHelp home page GithubHelp logo

pca_transform's People

Contributors

mckennapsean avatar mkobos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pca_transform's Issues

Determining eigenvectors

mkobos, I'm trying to use your library to do PCA in Java but I'm not quite sure how it works exactly. I have a set of n-points (xyz cartesian) and I want to find the plane along which they best fit; I was under the assumption that the eigenvectors would do this for me. However, your example doesn't explain itself well.

You create training data to initialize your PCA class with and then transform test data. The training data seems to have six components per instance as does the test data. However the transformed data only has two components (I'm assuming the components that aren't useful are being dropped).

However, I don't see a way to either have it not drop these components nor how to find out which components were removed in order to build a vector the correct vector.

As I said, I have cartesian coordinates and would like to find the best fit plane for them (well, the normal specifically). If you could add a quick example for me (or a way to query which components are being dropped) that would be very helpful. If I'm doing something wrong, please let me know.

Thanks!
Stephen

Here's my code sample; points contains all my vertices, centroid is the average coordinate of all the vertices. I've set the points to all have a y-value of 0 as a test case. I'm assuming to get an eigenvector of [0,1,0] for the plane normal (or something close to it).

     final List<Tuple3d> points = new ArrayList<>();
     final Tuple3d centroid = new Tuple3d(0,0,0);

     for(int x = -10; x <= 10; x++) {
        for(int z = -10; z <= 10; z++) {
           points.add(new Tuple3d(x,0,z));
        }
     }

     final double[][] samples = new double[points.size()][3];
     for(int i = 0; i < points.size(); i++) {
         final Tuple3d tuple = points.get(i);
         samples[i][0] = tuple.x - centroid.x;
         samples[i][1] = tuple.y - centroid.y;
         samples[i][2] = tuple.z - centroid.z;
      }

      final Matrix sampleMatrix = new Matrix(samples);
      final PCA pca = new PCA(sampleMatrix, false);
      final Matrix eigenMatrix = pca.getEigenvectorsMatrix();

      for(int i = 0; i < pca.getOutputDimsNo(); i++) {
         System.out.println("eigenvalue " + i + ": " + pca.getEigenvalue(i));
      }

      final double[][] vectors = eigenMatrix.getArray();
      for(int i = 0; i < vectors.length; i++) {
         System.out.println("eigenvector " + i + ": " + Arrays.toString(vectors[i]));
      }

And the output

eigenvalue 0: 36.75000000000001
eigenvalue 1: 36.749999999999964
eigenvector 0: [1.0, 0.0]
eigenvector 1: [0.0, 0.0]
eigenvector 2: [0.0, 1.0]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.