public static void Main() { modshogun.init_shogun_with_defaults(); double width = 1.4; int size_cache = 10; double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat"); RealFeatures features = new RealFeatures(traindata_real); PCA preproc = new PCA(); preproc.init(features); preproc.apply_to_feature_matrix(features); }
public void Test_Numerical_PCA() { Matrix m = new[, ] { { 2.5, 2.4 }, { 0.5, 0.7 }, { 2.2, 2.9 }, { 1.9, 2.2 }, { 3.1, 3.0 }, { 2.3, 2.7 }, { 2.0, 1.6 }, { 1.0, 1.1 }, { 1.5, 1.6 }, { 1.1, 0.9 } }; PCA pca = new PCA(); pca.Generate(m); }
public void GetComponentFromImageNormalCaseUShortArray() { PCA p = new PCA(); byte[] matrixArr = new byte[16] { 10, 20, 59, 223, 24, 80, 99, 31, 54, 113, 215, 70, 167, 131, 200, 101 }; byte[] matrixArr2 = new byte[16] { 10, 20, 59, 223, 24, 80, 99, 31, 54, 113, 215, 70, 167, 131, 200, 101 }; double[] expectation = new double[1] { 5130 }; byte[] imgArr = new byte[16] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; List <UShortArrayAsImage> img = new List <UShortArrayAsImage>(); img.Add(new UShortArrayAsImage(matrixArr, 4, 4)); img.Add(new UShortArrayAsImage(matrixArr2, 4, 4)); p.Train(img); double[] res = p.GetComponentsFromImage(img[0], 1); Console.WriteLine(res.Length); CollectionAssert.AreEqual(expectation, res, new Comparer(floatingPointTolerance)); }
public void Stitch1() { this.icp.Reset_RealData(); this.pointCloudTarget = new PointCloud(pathUnitTests + "\\Stitch1\\0.obj"); pointCloudTarget = PCA.RotateToOriginAxes(pointCloudTarget); this.pointCloudSource = new PointCloud(pathUnitTests + "\\Stitch1\\1.obj"); pointCloudSource = PCA.RotateToOriginAxes(pointCloudSource); IterativeClosestPointTransform.Instance.ICPSettings.ICPVersion = ICP_VersionUsed.Zinsser; this.pointCloudResult = IterativeClosestPointTransform.Instance.PerformICP(pointCloudSource, pointCloudTarget); this.pointCloudResult.ToObjFile(pathUnitTests + "\\Stitch1\\", "result.obj"); Show3PointCloudsInWindow(true); Assert.IsTrue(1e-3f > PointCloud.MeanDistance(pointCloudTarget, pointCloudResult)); }
public void MeanSubtractionNormalCaseTestNonSquare() { PCA p = new PCA(); double[,] matrixArray = new double[3, 5] { { 2.0, 3.4, 0.0, 2.9, 5.1 }, { 3.1, 9.2, 7.9, -2.3, 1.0 }, { -6.1, -5.7, 1.0, -8.3, 3.3 } }; double[,] resArray = new double[3, 5] { { 2.3333333333, 1.1, -2.9666666666, 5.4666666666, 1.9666666666 }, { 3.433333333, 6.9, 4.93333333333, 0.2666666666, -2.1333333333 }, { -5.766666666, -8.00, -1.9666666666, -5.733333333, 0.1666666666 } }; matrixArray = p.MeanSubtraction(matrixArray); CollectionAssert.AreEqual(resArray, matrixArray, new Comparer(floatingPointTolerance)); }
/// <summary> /// Signs the user out of the application and unenrolls from MAM. /// </summary> public async void SignOut() { // Clear the app's token cache so the user will be prompted to sign in again. var currentAccounts = await PCA.GetAccountsAsync(); if (currentAccounts.Count() > 0) { await PCA.RemoveAsync(currentAccounts.FirstOrDefault()); } string user = User; if (user != null) { // Remove the user's MAM policy from the app IMAMEnrollmentManager mgr = MAMComponents.Get <IMAMEnrollmentManager>(); mgr.UnregisterAccountForMAM(user); } Toast.MakeText(Android.App.Application.Context, Resource.String.auth_out_success, ToastLength.Short).Show(); }
public void MeanSubtractionEdgeCaseAllZeroTest() { PCA p = new PCA(); double[,] matrixArray = new double[3, 3] { { 0.0, 0.0, 0.0 }, { 0.0, -0.0, 0.0 }, { -0.0, 0.0, -0.0 } }; double[,] resArray = new double[3, 3] { { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 } }; matrixArray = p.MeanSubtraction(matrixArray); CollectionAssert.AreEqual(resArray, matrixArray, new Comparer(floatingPointTolerance)); }
public void Sample2D_Old() { UIMode = false; Create2DSamples(); PCA pca = new PCA(); pca.PCA_OfPointCloud(pointCloudSource); //List<Vector3> resultList = pca.ProjectPointsOnPCAAxes(); // pointCloudTarget - is the result list of the first vector // pointCloudResult - is the result list of the second vector pointCloudTarget = PointCloud.FromListVector3(pca.PointsResult0); pointCloudResult = PointCloud.FromListVector3(pca.PointsResult1); if (UIMode) { //ShowResultsInWindow_Cube(true); Show4PointCloudsInWindow(true); } if (!GLSettings.PointCloudCentered) { Assert.IsTrue(1e-3f > PointCloud.MeanDistance(expectedResultCloud, pointCloudTarget)); } else { expectedResultCloud = new PointCloud(); expectedResultCloud.AddVector(new Vector3(-1.20497441625437f, -1.30683911366186f, 0)); expectedResultCloud.AddVector(new Vector3(-0.282584287549998f, 0.260557580021532f, 0)); expectedResultCloud.AddVector(new Vector3(0, 0, 0)); Assert.IsTrue(this.threshold > PointCloud.MeanDistance(pointCloudSource.PCAAxes, expectedResultCloud)); } }
/// <summary> /// Attempt interactive authentication through the broker. /// </summary> /// <returns>The AuthenticationResult on succes, null otherwise.</returns> public async Task <AuthenticationResult> SignInWithPrompt(Activity activity) { AuthenticationResult result = null; try { Log.Info(_logTagAuth, "Attempting interactive authentication"); result = await PCA.AcquireTokenInteractive(_scopes) .WithParentActivityOrWindow(activity) .WithUseEmbeddedWebView(true) .ExecuteAsync(); } catch (MsalException e) { string msg = Resource.String.err_auth + e.Message; Log.Error(_logTagAuth, Throwable.FromException(e), msg); Toast.MakeText(activity, msg, ToastLength.Long).Show(); return(null); } return(result); }
public static void MakePrediction(bool normalize = false, bool usePca = false) { if (normalize || usePca) { StandardizePredictors(); } // use stored PCA analysis to transform standardized features // only use if features are normalized first if (usePca) { CurrPredictionPoints = PCA.Transform(CurrPredictionPoints); } if (Classification.IsClassifier) { Predict(); } else { Regression(); } }
public void Person_PCA() { this.pointCloudTarget = new PointCloud(pathUnitTests + "\\2.obj"); this.pointCloudSource = PointCloud.CloneAll(pointCloudTarget); PointCloud.RotateDegrees(pointCloudSource, 25, 10, 25); PCA pca = new PCA(); this.pointCloudResult = pca.AlignPointClouds_OneVector(this.pointCloudSource, this.pointCloudTarget, 0, 0); this.pointCloudResult = pca.AlignPointClouds_OneVector(this.pointCloudResult, this.pointCloudTarget, 1, 1); this.pointCloudResult = pca.AlignPointClouds_OneVector(this.pointCloudResult, this.pointCloudTarget, 2, 2); this.pointCloudResult = pca.AlignPointClouds_OneVector(this.pointCloudResult, this.pointCloudTarget, 0, 0); Show3PointCloudsInWindow(true); //ShowPointCloudsInWindow_PCAVectors(true); Assert.IsTrue(4e-3f < PointCloud.MeanDistance(pointCloudTarget, pointCloudResult)); }
public void Person_PCA_V_TwoClouds() { this.pointCloudTarget = new PointCloud(pathUnitTests + "\\2.obj"); this.pointCloudSource = new PointCloud(pathUnitTests + "\\1.obj"); PCA pca = new PCA(); this.pointCloudResult = pca.AlignPointClouds_OneVector(this.pointCloudSource, this.pointCloudTarget, 0, 0); this.pointCloudResult = pca.AlignPointClouds_OneVector(this.pointCloudResult, this.pointCloudTarget, 1, 1); this.pointCloudResult = pca.AlignPointClouds_OneVector(this.pointCloudResult, this.pointCloudTarget, 2, 2); this.pointCloudResult = pca.AlignPointClouds_OneVector(this.pointCloudResult, this.pointCloudTarget, 0, 0); Show3PointCloudsInWindow(true); //ShowPointCloudsInWindow_PCAVectors(true); Assert.IsTrue(this.threshold > meanDistance); pointCloudSource = PCA.RotateToOriginAxes(pointCloudSource); }
//------------------------------------------------------------------------------ public override void refine(List <OctreeLeaf> leafs, bool btest) { double[] Param = initial(); List <Vectors> x = new List <Vectors>(leafs.Count); int j = 0; // for every for (int i = 0; i < leafs.Count; i++) { bool b = false; if ((btest == false)) { b = true; } else // check this else { if (testLeaf(leafs[i])) { if (leafs[i].testMinPts) { if (leafs[i].planar()) { b = true; } } } } if (b) { x.Add(leafs[i].Sigma); j++; } } PCA p = new PCA(x, x.Count); _N = p.Norm; _d = p.dcent; }
public void AlignPCAToOriginAxes() { Create2DSamples(); pointCloudTarget = null; pointCloudResult = PCA.RotateToOriginAxes(pointCloudSource); //-----------Show in Window if (UIMode) { Show4PointCloudsInWindow(true); //ShowResultsInWindow_Cube(true); } expectedResultCloud = new PointCloud(); expectedResultCloud.AddVector(new Vector3(1.77758032528043f, 0, 0)); expectedResultCloud.AddVector(new Vector3(0, 0.384374988880412f, 0)); expectedResultCloud.AddVector(new Vector3(0, 0, 0)); //----------------check Result Assert.IsTrue(this.threshold > PointCloud.MeanDistance(expectedResultCloud, pointCloudResult.PCAAxes)); }
public void TrainNumberOfComponents() { PCA p = new PCA(); double[,] matrix2 = new double[10, 2] { { 1.507, 0.988 }, { 2.107, -9.312 }, { 1.407, 1.798 }, { 1.397, 2.098 }, { -9.563, 1.988 }, { 0.797, 0.888 }, { 2.607, 0.488 }, { -0.493, 1.588 }, { 0.627, -0.412 }, { -0.393, -0.112 } }; int expectation = 2; p.Train(matrix2); Assert.AreEqual(expectation, p.ComponentVectors.Length); }
public void Chair_Angles() { this.icp.Reset_RealData(); this.pointCloudTarget = new PointCloud(pathUnitTests + "\\G1.obj"); pointCloudTarget = PCA.RotateToOriginAxes(pointCloudTarget); this.pointCloudSource = new PointCloud(pathUnitTests + "\\G2.obj"); pointCloudSource = PCA.RotateToOriginAxes(pointCloudSource); IterativeClosestPointTransform.Instance.ICPSettings.ICPVersion = ICP_VersionUsed.Zinsser; IterativeClosestPointTransform.Instance.ICPSettings.MaximumNumberOfIterations = 5; //IterativeClosestPointTransform.Instance.ICPSettings.FixedTestPoints = true; this.pointCloudResult = IterativeClosestPointTransform.Instance.PerformICP(pointCloudSource, pointCloudTarget); this.pointCloudResult.ToObjFile(pathUnitTests, "Result.obj"); IterativeClosestPointTransform.Instance.PMerged.ToObjFile(pathUnitTests, "Result_Merged.obj"); Show3PointCloudsInWindow(true); Assert.IsTrue(1e-3f > PointCloud.MeanDistance(pointCloudTarget, pointCloudResult)); }
public void TrainNormalCaseJaggedArray() { PCA p = new PCA(); double[][] matrix = new double[10][]; matrix[0] = new double[] { 0.69, 0.49 }; matrix[1] = new double[] { -1.31, -1.21 }; matrix[2] = new double[] { 0.39, 0.99 }; matrix[3] = new double[] { 0.09, 0.29 }; matrix[4] = new double[] { 1.29, 1.09 }; matrix[5] = new double[] { 0.49, 0.79 }; matrix[6] = new double[] { 0.19, -0.31 }; matrix[7] = new double[] { -0.81, -0.81 }; matrix[8] = new double[] { -0.31, -0.31 }; matrix[9] = new double[] { -0.71, -1.01 }; double[] expectation = { 0.6778734, 0.73517866 }; // Verified with octave p.Train(matrix); CollectionAssert.AreEqual(expectation, p.ComponentVectors[0], new Comparer(floatingPointTolerance)); }
public void TrainNormalCaseEigenValues() { PCA p = new PCA(); double[,] matrix = new double[10, 2] { { 0.69, 0.49 }, { -1.31, -1.21 }, { 0.39, 0.99 }, { 0.09, 0.29 }, { 1.29, 1.09 }, { 0.49, 0.79 }, { 0.19, -0.31 }, { -0.81, -0.81 }, { -0.31, -0.31 }, { -0.71, -1.01 } }; double expectation = 1.28402771; // Verified with octave p.Train(matrix); Assert.AreEqual(expectation, p.Eigenvalues[0], floatingPointTolerance); }
/// <summary> /// Signs the user out of the application and unenrolls from MAM. /// </summary> /// <param name="listener"></param> public async void SignOut(IAuthListener listener) { // Clear the app's token cache so the user will be prompted to sign in again. var currentAccounts = await PCA.GetAccountsAsync(); if (currentAccounts.Count() > 0) { await PCA.RemoveAsync(currentAccounts.FirstOrDefault()); } string user = User; if (user != null) { // Remove the user's MAM policy from the app IMAMEnrollmentManager mgr = MAMComponents.Get <IMAMEnrollmentManager>(); mgr.UnregisterAccountForMAM(user); } isAuthenticated = false; listener.OnSignedOut(); }
public void TrainNormalCase() { PCA p = new PCA(); double[,] matrix = new double[10, 2] { { 0.69, 0.49 }, { -1.31, -1.21 }, { 0.39, 0.99 }, { 0.09, 0.29 }, { 1.29, 1.09 }, { 0.49, 0.79 }, { 0.19, -0.31 }, { -0.81, -0.81 }, { -0.31, -0.31 }, { -0.71, -1.01 } }; double[] expectation = { 0.6778734, 0.73517866 }; // Verified with octave p.Train(matrix); CollectionAssert.AreEqual(expectation, p.ComponentVectors[0], new Comparer(floatingPointTolerance)); }
public static void Demo() { PCANetwork network = PCANetwork.Create(2, 1); var dataSet = DataGenerator.GenerateDataSet2(); var pca = new PCA(network, 0.7); PCATrainer trainer = new PCATrainer(network, 50, pca, 0.0000005); Normalizer2 normalizer = new Normalizer2(); normalizer.Fit(dataSet.XList); var normalizedX = normalizer.Normalize(dataSet.XList); trainer.Fit(normalizedX); List <List <double> > convertedX = trainer.GetConvertedDim(normalizedX); List <List <double> > denormalX = normalizer.DeNormalize(convertedX); network.Display(); Console.WriteLine("OLD VECTORS===>"); Utils.DisplayListList(dataSet.XList); Console.WriteLine("OLD VECTORS(NORMALIZED)===>"); Utils.DisplayListList(normalizedX); Console.WriteLine("NEW VECTORS(NORMALIZED)===>"); Utils.DisplayListList(convertedX); Console.WriteLine("NEW VECTORS===>"); Utils.DisplayListList(denormalX); }
public static float Test7_Face_KnownTransformation_PCA_15000(ref PointCloud mypointCloudTarget, ref PointCloud mypointCloudSource, ref PointCloud mypointCloudResult) { string path = AppDomain.CurrentDomain.BaseDirectory + "PointClouds\\UnitTests"; mypointCloudTarget = new PointCloud(path + "\\KinectFace_1_15000.obj"); mypointCloudSource = PointCloud.CloneAll(mypointCloudTarget); PointCloud.ScaleByFactor(mypointCloudSource, 0.9f); Matrix3 R = new Matrix3(); R = R.RotationXYZDegrees(60, 60, 60); PointCloud.Rotate(mypointCloudSource, R); PointCloud.Translate(mypointCloudSource, 0.3f, 0.5f, -0.4f); PCA pca = new PCA(); mypointCloudResult = pca.AlignPointClouds_SVD(mypointCloudSource, mypointCloudTarget); mypointCloudSource = mypointCloudResult; mypointCloudResult = IterativeClosestPointTransform.Instance.PerformICP(mypointCloudSource, mypointCloudTarget); return(IterativeClosestPointTransform.Instance.MeanDistance); }
/// <summary> /// Calculates 11 directional and 6 non-directional WHIM descriptors for. /// the specified weighting scheme /// </summary> /// <returns>An ArrayList containing the descriptors in the order described above.</returns> public Result Calculate(IAtomContainer container, AtomWeightingType type = AtomWeightingType.Unity) { if (!GeometryUtil.Has3DCoordinates(container)) { throw new ThreeDRequiredException("Molecule must have 3D coordinates"); } double sum = 0.0; var ac = (IAtomContainer)container.Clone(); // do aromaticity detecttion for calculating polarizability later on //HueckelAromaticityDetector had = new HueckelAromaticityDetector(); //had.DetectAromaticity(ac); // get the coordinate matrix var cmat = Arrays.CreateJagged <double>(ac.Atoms.Count, 3); for (int i = 0; i < ac.Atoms.Count; i++) { var coords = ac.Atoms[i].Point3D.Value; cmat[i][0] = coords.X; cmat[i][1] = coords.Y; cmat[i][2] = coords.Z; } // set up the weight vector var wt = new double[ac.Atoms.Count]; IReadOnlyDictionary <int, double> hash = null; switch (type) { case AtomWeightingType.Mass: hash = hashatwt; break; case AtomWeightingType.Volume: hash = hashvdw; break; case AtomWeightingType.Electronegativity: hash = hasheneg; break; case AtomWeightingType.Polarizability: hash = hashpol; break; default: break; } switch (type) { case AtomWeightingType.Unity: for (int i = 0; i < ac.Atoms.Count; i++) { wt[i] = 1.0; } break; default: for (int i = 0; i < ac.Atoms.Count; i++) { wt[i] = hash[ac.Atoms[i].AtomicNumber]; } break; } PCA pcaobject = null; try { pcaobject = new PCA(cmat, wt); } catch (CDKException cdke) { Debug.WriteLine(cdke); } // directional WHIM's var lambda = pcaobject.GetEigenvalues(); var gamma = new double[3]; var nu = new double[3]; var eta = new double[3]; for (int i = 0; i < 3; i++) { sum += lambda[i]; } for (int i = 0; i < 3; i++) { nu[i] = lambda[i] / sum; } var scores = pcaobject.GetScores(); for (int i = 0; i < 3; i++) { sum = 0.0; for (int j = 0; j < ac.Atoms.Count; j++) { sum += scores[j][i] * scores[j][i] * scores[j][i] * scores[j][i]; } sum = sum / (lambda[i] * lambda[i] * ac.Atoms.Count); eta[i] = 1.0 / sum; } // look for symmetric & asymmetric atoms for the gamma descriptor for (int i = 0; i < 3; i++) { double ns = 0.0; double na = 0.0; for (int j = 0; j < ac.Atoms.Count; j++) { bool foundmatch = false; for (int k = 0; k < ac.Atoms.Count; k++) { if (k == j) { continue; } if (scores[j][i] == -1 * scores[k][i]) { ns++; foundmatch = true; break; } } if (!foundmatch) { na++; } } var n = (double)ac.Atoms.Count; gamma[i] = -1.0 * ((ns / n) * Math.Log(ns / n) / Math.Log(2.0) + (na / n) * Math.Log(1.0 / n) / Math.Log(2.0)); gamma[i] = 1.0 / (1.0 + gamma[i]); } { // non directional WHIMS's var t = lambda[0] + lambda[1] + lambda[2]; var a = lambda[0] * lambda[1] + lambda[0] * lambda[2] + lambda[1] * lambda[2]; var v = t + a + lambda[0] * lambda[1] * lambda[2]; double k = 0.0; sum = 0.0; for (int i = 0; i < 3; i++) { sum += lambda[i]; } for (int i = 0; i < 3; i++) { k = (lambda[i] / sum) - (1.0 / 3.0); } k = k / (4.0 / 3.0); var g = Math.Pow(gamma[0] * gamma[1] * gamma[2], 1.0 / 3.0); var d = eta[0] + eta[1] + eta[2]; // return all the stuff we calculated return(new Result( lambda[0], lambda[1], lambda[2], nu[0], nu[1], gamma[0], gamma[1], gamma[2], eta[0], eta[1], eta[2], t, a, v, k, g, d)); } }
public void PCA_2D_InWork() { List <Vector3> pointsSource = new List <Vector3>(); Vector3 v = new Vector3(1, 2, 0); pointsSource.Add(v); v = new Vector3(2, 3, 0); pointsSource.Add(v); v = new Vector3(3, 2, 0); pointsSource.Add(v); v = new Vector3(4, 4, 0); pointsSource.Add(v); v = new Vector3(5, 4, 0); pointsSource.Add(v); v = new Vector3(6, 7, 0); pointsSource.Add(v); v = new Vector3(7, 6, 0); pointsSource.Add(v); v = new Vector3(9, 7, 0); pointsSource.Add(v); PCA pca = new PCA(); ////expected result //List<Vector3> listExpectedResult = new List<Vector3>(); //Vector3 v1 = new Vector3(2.371258964, 2.51870600832217, 0); //listExpectedResult.Add(v1); //v1 = new Vector3(0.605025583745627, 0.603160886338143, 0); //listExpectedResult.Add(v1); //v1 = new Vector3(2.48258428755, 2.63944241997847, 0); //listExpectedResult.Add(v1); //v1 = new Vector3(1.99587994658902, 2.11159364495307, 0); //listExpectedResult.Add(v1); //v1 = new Vector3(2.94598120291464, 3.1420134339185, 0); //listExpectedResult.Add(v1); //v1 = new Vector3(2.42886391124136, 2.58118069424077, 0); //listExpectedResult.Add(v1); //v1 = new Vector3(1.74281634877673, 1.83713685698813, 0); //listExpectedResult.Add(v1); //v1 = new Vector3(1.03412497746524, 1.06853497544495, 0); //listExpectedResult.Add(v1); //v1 = new Vector3(1.51306017656077, 1.58795783010856, 0); //listExpectedResult.Add(v1); //v1 = new Vector3(0.980404601156606, 1.01027324970724, 0); //listExpectedResult.Add(v1); //for (int i = 0; i < listExpectedResult.Count; i++) //{ // Assert.IsTrue(PointCloud.CheckCloud(listExpectedResult[i].X, listResult[i].X, this.threshold)); // Assert.IsTrue(PointCloud.CheckCloud(listExpectedResult[i].Y, listResult[i].Y, this.threshold)); //} // ShowVector3InWindow(listResult); this.pointCloudSource = PointCloud.FromListVector3(pointsSource); this.pointCloudTarget = pca.CalculatePCA(PointCloud.FromListVector3(pointsSource), 0); this.pointCloudResult = pca.CalculatePCA(PointCloud.FromListVector3(pointsSource), 1); if (UIMode) { Show4PointCloudsInWindow(true); } }
public void CovarianceMatrixNormalCaseNonSquareMoreColumnsTest() { PCA p = new PCA(); double[,] matrixArr = new double[2, 10] { { 0.69, 0.49, -1.31, -1.21, 0.39, 0.99, 0.09, 0.29, 1.29, 1.09 }, { 0.49, 0.79, 0.19, -0.31, -0.81, -0.81, -0.31, -0.31, -0.71, -1.01 } }; double[,] expectation = new double[10, 10]; expectation[0, 0] = 0.199999999999999900e-1; expectation[0, 1] = -0.299999999999999989e-1; expectation[0, 2] = -0.149999999999999967e0; expectation[0, 3] = -0.899999999999999689e-1; expectation[0, 4] = 0.119999999999999996e0; expectation[0, 5] = 0.179999999999999966e0; expectation[0, 6] = 0.399999999999999939e-1; expectation[0, 7] = 0.599999999999999839e-1; expectation[0, 8] = 0.199999999999999956e0; expectation[0, 9] = 0.209999999999999964e0; expectation[1, 0] = -0.299999999999999989e-1; expectation[1, 1] = 0.450000000000000122e-1; expectation[1, 2] = 0.225000000000000033e0; expectation[1, 3] = 0.135000000000000009e0; expectation[1, 4] = -0.180000000000000049e0; expectation[1, 5] = -0.270000000000000073e0; expectation[1, 6] = -0.600000000000000117e-1; expectation[1, 7] = -0.900000000000000105e-1; expectation[1, 8] = -0.300000000000000044e0; expectation[1, 9] = -0.315000000000000058e0; expectation[2, 0] = -0.149999999999999967e0; expectation[2, 1] = 0.225000000000000033e0; expectation[2, 2] = 0.112500000000000000e1; expectation[2, 3] = 0.675000000000000044e0; expectation[2, 4] = -0.900000000000000133e0; expectation[2, 5] = -0.135000000000000009e1; expectation[2, 6] = -0.300000000000000044e0; expectation[2, 7] = -0.449999999999999956e0; expectation[2, 8] = -0.150000000000000000e1; expectation[2, 9] = -0.157500000000000018e1; expectation[3, 0] = -0.899999999999999689e-1; expectation[3, 1] = 0.135000000000000009e0; expectation[3, 2] = 0.675000000000000044e0; expectation[3, 3] = 0.404999999999999971e0; expectation[3, 4] = -0.540000000000000036e0; expectation[3, 5] = -0.810000000000000053e0; expectation[3, 6] = -0.179999999999999993e0; expectation[3, 7] = -0.270000000000000018e0; expectation[3, 8] = -0.899999999999999911e0; expectation[3, 9] = -0.945000000000000062e0; expectation[4, 0] = 0.119999999999999996e0; expectation[4, 1] = -0.180000000000000049e0; expectation[4, 2] = -0.900000000000000133e0; expectation[4, 3] = -0.540000000000000036e0; expectation[4, 4] = 0.720000000000000195e0; expectation[4, 5] = 0.108000000000000029e1; expectation[4, 6] = 0.240000000000000047e0; expectation[4, 7] = 0.360000000000000042e0; expectation[4, 8] = 0.120000000000000018e1; expectation[4, 9] = 0.126000000000000023e1; expectation[5, 0] = 0.179999999999999966e0; expectation[5, 1] = -0.270000000000000073e0; expectation[5, 2] = -0.135000000000000009e1; expectation[5, 3] = -0.810000000000000053e0; expectation[5, 4] = 0.108000000000000029e1; expectation[5, 5] = 0.162000000000000011e1; expectation[5, 6] = 0.360000000000000042e0; expectation[5, 7] = 0.540000000000000036e0; expectation[5, 8] = 0.180000000000000004e1; expectation[5, 9] = 0.189000000000000012e1; expectation[6, 0] = 0.399999999999999939e-1; expectation[6, 1] = -0.600000000000000117e-1; expectation[6, 2] = -0.300000000000000044e0; expectation[6, 3] = -0.179999999999999993e0; expectation[6, 4] = 0.240000000000000047e0; expectation[6, 5] = 0.360000000000000042e0; expectation[6, 6] = 0.800000000000000155e-1; expectation[6, 7] = 0.119999999999999996e0; expectation[6, 8] = 0.400000000000000022e0; expectation[6, 9] = 0.420000000000000040e0; expectation[7, 0] = 0.599999999999999839e-1; expectation[7, 1] = -0.900000000000000105e-1; expectation[7, 2] = -0.449999999999999956e0; expectation[7, 3] = -0.270000000000000018e0; expectation[7, 4] = 0.360000000000000042e0; expectation[7, 5] = 0.540000000000000036e0; expectation[7, 6] = 0.119999999999999996e0; expectation[7, 7] = 0.179999999999999993e0; expectation[7, 8] = 0.599999999999999978e0; expectation[7, 9] = 0.630000000000000004e0; expectation[8, 0] = 0.199999999999999956e0; expectation[8, 1] = -0.300000000000000044e0; expectation[8, 2] = -0.150000000000000000e1; expectation[8, 3] = -0.899999999999999911e0; expectation[8, 4] = 0.120000000000000018e1; expectation[8, 5] = 0.180000000000000004e1; expectation[8, 6] = 0.400000000000000022e0; expectation[8, 7] = 0.599999999999999978e0; expectation[8, 8] = 0.2e1; expectation[8, 9] = 0.210000000000000009e1; expectation[9, 0] = 0.209999999999999964e0; expectation[9, 1] = -0.315000000000000058e0; expectation[9, 2] = -0.157500000000000018e1; expectation[9, 3] = -0.945000000000000062e0; expectation[9, 4] = 0.126000000000000023e1; expectation[9, 5] = 0.189000000000000012e1; expectation[9, 6] = 0.420000000000000040e0; expectation[9, 7] = 0.630000000000000004e0; expectation[9, 8] = 0.210000000000000009e1; expectation[9, 9] = 0.220500000000000007e1; double[,] cpyMatrix = new double[2, 10]; matrixArr.CopyTo(cpyMatrix); matrixArr = p.MeanSubtraction(matrixArr); matrixArr = p.CovarianceMatrix(matrixArr); CollectionAssert.AreEqual(expectation, matrixArr, new Comparer(floatingPointTolerance)); double[,] ourCov = matrixArr; double[,] cov = cpyMatrix.Covariance(); CollectionAssert.AreEqual(expectation, cov, new Comparer(floatingPointTolerance)); }
public void GetProblemFromImageModelResultListTest() { ushort[,] image1 = new ushort[, ] { { 1, 2, 3, 4, 5 }, { 6, 2, 8, 9, 10 }, { 11, 8, 2, 10, 11 }, { 16, 13, 11, 15, 16 }, { 21, 2, 1, 1, 25 }, }; ushort[,] image2 = new ushort[, ] { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 }, { 11, 8, 9, 10, 11 }, { 16, 13, 14, 15, 16 }, { 21, 2, 23, 24, 25 }, }; ImageWithResultModel resultImage1 = new ImageWithResultModel(); resultImage1.Image = new UShortArrayAsImage(image1); resultImage1.Result = 1; ImageWithResultModel resultImage2 = new ImageWithResultModel(); resultImage2.Image = new UShortArrayAsImage(image2); resultImage2.Result = 0; var images = new List <ImageWithResultModel>() { resultImage1, resultImage2 }; File.Delete(@"pca_model-100x100-CC-Train-MassCalc-BI.bin"); PCA pca = TrainingHelper.GetPca(images); PCA pca2 = TrainingHelper.GetPca(images); SVMProblem problem = ProblemHandler.GetProblemFromImageModelResultList(images, pca, 10); //Expected value SVMProblem realValue = new SVMProblem(); realValue.Add(new SVMNode[] { new SVMNode(1, 20.056853498561878), new SVMNode(2, 13.190302568584602), new SVMNode(3, -1.0813980605883611), new SVMNode(4, 0.38976510872122916), new SVMNode(5, 8.8596355929840787), new SVMNode(6, -7.3433006502883726), new SVMNode(7, 10.837768344992746), new SVMNode(8, 20.626727358988219), new SVMNode(9, -1.7552480617394235), new SVMNode(10, 25), }, 0); realValue.Add(new SVMNode[] { new SVMNode(1, 22.292105243883533), new SVMNode(2, 11.126898461982794), new SVMNode(3, -2.3028333386433371), new SVMNode(4, -6.2077696783291429), new SVMNode(5, 12.172991455602181), new SVMNode(6, -4.385545310384054), new SVMNode(7, 13.837367251719812), new SVMNode(8, 20.646721554636255), new SVMNode(9, -1.8000434956830436), new SVMNode(10, 25), }, 1); bool fail = false; for (int i = 0; i < realValue.Y.Count; i++) { // Expected values var y = realValue.Y[i]; var x = realValue.X[i]; // Actual values var py = problem.Y[i]; var px = problem.X[i]; for (int j = 0; j < x.Length; j++) { if (x[j].Value != px[j].Value) { fail = true; } } } if (!fail) { Assert.Pass(); } else { Assert.Fail(); } }
public static double[,] CovarianceFromCurves([ExcelArgument(Description = "Blob of curves, each row is a curve of the same length.")] double[,] curves) { return(PCA.CovarianceFromCurves(curves)); }
public PCATrainer(PCANetwork network, int epoch, PCA algorithm, double stopCondition) : base(network, epoch, algorithm) { this.stopCondition = stopCondition; }
public void LoadModelFromFileException() { Assert.Throws <FileNotFoundException>(() => PCA.LoadModelFromFile("FileNotFound.bin")); }
public void CovarianceMatrixNormalCaseSquareTest() { PCA p = new PCA(); double[,] matrixArr = new double[9, 9] { { -3617, 7121, -1770, -3850, -5723, 8288, 1787, 5367, -1375 }, { -1733, 722, 946, 5770, -399, -5187, -4681, 9403, 3872 }, { -3925, -1839, 6520, 2019, 6463, -8250, -6075, -1832, 2983 }, { 6100, -3915, -1382, -9308, -4979, 8051, -533, 5281, 9673 }, { 1243, -919, 9893, -3647, -2795, 1933, 4824, 33, 8109 }, { -6118, -9715, 8984, -1367, 4956, 6600, -4139, -2693, 4956 }, { 4136, -664, 5962, 4935, -6293, 8180, -5666, -7926, 9214 }, { 2202, 8521, -4741, 5402, 9037, 4987, -4376, -7846, 4644 }, { -3823, -1998, -3350, 570, -7444, 8243, 7435, 2623, 6424 } }; double[,] expectation = new double[9, 9]; // array generated by maple expectation[0, 0] = 0.176053975000000000e8; expectation[0, 1] = 0.457826837500000000e7; expectation[0, 2] = -0.399328887499999953e7; expectation[0, 3] = -0.331221700000000093e7; expectation[0, 4] = -0.627830337500000000e7; expectation[0, 5] = 0.7003523e7; expectation[0, 6] = -0.186999875000000000e7; expectation[0, 7] = -0.4798844e7; expectation[0, 8] = 0.986533037500000000e7; expectation[1, 0] = 0.457826837500000000e7; expectation[1, 1] = 0.301754470277777761e8; expectation[1, 2] = -0.182812283888888881e8; expectation[1, 3] = 0.848513673611111008e7; expectation[1, 4] = 0.186260465277778334e7; expectation[1, 5] = 0.428261597222222248e6; expectation[1, 6] = 0.823882833333333256e6; expectation[1, 7] = -0.153511636111111194e7; expectation[1, 8] = -0.885727530555555597e7; expectation[2, 0] = -0.399328887499999953e7; expectation[2, 1] = -0.182812283888888881e8; expectation[2, 2] = 0.308733886944444440e8; expectation[2, 3] = -0.117307893055555481e7; expectation[2, 4] = 0.462695686111111008e7; expectation[2, 5] = -0.106785538611111101e8; expectation[2, 6] = -0.589139766666666698e7; expectation[2, 7] = -0.852483606944444589e7; expectation[2, 8] = 0.435253290277777892e7; expectation[3, 0] = -0.331221700000000093e7; expectation[3, 1] = 0.848513673611111008e7; expectation[3, 2] = -0.117307893055555481e7; expectation[3, 3] = 0.259787679444444478e8; expectation[3, 4] = 0.120599827361111119e8; expectation[3, 5] = -0.124263529861111119e8; expectation[3, 6] = -0.124783096666666660e8; expectation[3, 7] = -0.119806404444444440e8; expectation[3, 8] = -0.266636397222222295e7; expectation[4, 0] = -0.627830337500000000e7; expectation[4, 1] = 0.186260465277778334e7; expectation[4, 2] = 0.462695686111111008e7; expectation[4, 3] = 0.120599827361111119e8; expectation[4, 4] = 0.378507245277777761e8; expectation[4, 5] = -0.191299344027777798e8; expectation[4, 6] = -0.184137604166666679e8; expectation[4, 7] = -0.155837438611111119e8; expectation[4, 8] = -0.572766680555555504e7; expectation[5, 0] = 0.7003523e7; expectation[5, 1] = 0.428261597222222248e6; expectation[5, 2] = -0.106785538611111101e8; expectation[5, 3] = -0.124263529861111119e8; expectation[5, 4] = -0.191299344027777798e8; expectation[5, 5] = 0.394546397777777761e8; expectation[5, 6] = 0.127166160416666679e8; expectation[5, 7] = -0.693834988888888806e7; expectation[5, 8] = 0.558211630555555597e7; expectation[6, 0] = -0.186999875000000000e7; expectation[6, 1] = 0.823882833333333256e6; expectation[6, 2] = -0.589139766666666698e7; expectation[6, 3] = -0.124783096666666660e8; expectation[6, 4] = -0.184137604166666679e8; expectation[6, 5] = 0.127166160416666679e8; expectation[6, 6] = 0.243410542500000000e8; expectation[6, 7] = 0.108749302916666660e8; expectation[6, 8] = 0.144274745833333372e7; expectation[7, 0] = -0.4798844e7; expectation[7, 1] = -0.153511636111111194e7; expectation[7, 2] = -0.852483606944444589e7; expectation[7, 3] = -0.119806404444444440e8; expectation[7, 4] = -0.155837438611111119e8; expectation[7, 5] = -0.693834988888888806e7; expectation[7, 6] = 0.108749302916666660e8; expectation[7, 7] = 0.357919496944444403e8; expectation[7, 8] = -0.550449015277777798e7; expectation[8, 0] = 0.986533037500000000e7; expectation[8, 1] = -0.885727530555555597e7; expectation[8, 2] = 0.435253290277777892e7; expectation[8, 3] = -0.266636397222222295e7; expectation[8, 4] = -0.572766680555555504e7; expectation[8, 5] = 0.558211630555555597e7; expectation[8, 6] = 0.144274745833333372e7; expectation[8, 7] = -0.550449015277777798e7; expectation[8, 8] = 0.120046551111111119e8; matrixArr = p.MeanSubtraction(matrixArr); matrixArr = p.CovarianceMatrix(matrixArr); CollectionAssert.AreEqual(expectation, matrixArr, new Comparer(floatingPointTolerance)); }
public static double[,] PCAFromCurves([ExcelArgument(Description = "Blob of curves, each row is a curve of the same length.")] double[,] curves, [ExcelArgument(Description = "Indicates if the PCA is to be done on relative moves. If not then it will be done on absolute moves.")] bool useRelative) { return(PCA.PCAFromCurves(curves, useRelative)); }