Пример #1
0
        // Does RowNormalize, but doesn't kernel normalize
        public Matrix <string, string, double> ToSubKernel(Matrix <string, string, double> unnormalizedAndUnfilteredInput, int cidInBatchCount, int batchCount, int i, int j, List <EScienceLearn.RowFilters.RowFilter> RowFilterList)
        {
            //!!!could cache the twoMatrices, so if one or both is the same, wouldn't reload.
            var unfilteredInput = RowNormalizer.Normalize(unnormalizedAndUnfilteredInput);
            var input           = EScienceLearn.RowFilters.RowFilter.ApplyList(RowFilterList, unfilteredInput, null);


            var cidListList = SpecialFunctions.DivideListIntoEqualChunksFromChunkSize <string>(input.ColKeys, cidInBatchCount);

            Helper.CheckCondition(cidListList.Count == batchCount, "Expect the cidListList.Count == batchCount");
            Console.WriteLine("cids divided into {0} batches of about {1}", cidListList.Count, cidInBatchCount);
            Helper.CheckCondition(cidListList.Sum(l => l.Count) == input.ColCount, "real assert");


            Console.WriteLine("Loading batch {0}, size {1}x{2}", i, cidListList[i].Count, input.RowCount);
            var matrixI = input.SelectColsView(cidListList[i]).ToShoMatrix(verbose: true);

            Console.WriteLine("Loading batch {0}, size {1}x{2}", j, cidListList[j].Count, input.RowCount);

            if (i == j)
            {
                ShoMatrix kii = JustKernel(matrixI);
                return(kii);
            }
            else
            {
                var       matrixJ = input.SelectColsView(cidListList[j]).ToShoMatrix(verbose: true);
                ShoMatrix kij     = JustKernel(matrixI, matrixJ);
                return(kij);
            }
        }
Пример #2
0
        public Matrix <string, string, double> ToKernel(Matrix <string, string, double> unnormalizedInput, int?cidInBatchCountOrNull = null)
        {
            if (null == cidInBatchCountOrNull)
            {
                return(ToKernel(unnormalizedInput));
            }

            var input = RowNormalizer.Normalize(unnormalizedInput);


            var cidListList = SpecialFunctions.DivideListIntoEqualChunksFromChunkSize <string>(input.ColKeys, cidInBatchCountOrNull.Value);

            Console.WriteLine("cids divided into {0} batches of about {1}", cidListList.Count, cidInBatchCountOrNull);
            Helper.CheckCondition(cidListList.Sum(l => l.Count) == input.ColCount, "real assert");


            var counterWithMessages = new CounterWithMessages("kernel combintations ", 1, (cidListList.Count * cidListList.Count + cidListList.Count) / 2);

            var kernelPieces2D = new Matrix <string, string, double> [cidListList.Count, cidListList.Count];

            for (int i = 0; i < cidListList.Count; ++i)
            {
                Console.WriteLine("Loading batch {0}, size {1}x{2}", i, cidListList[i].Count, unnormalizedInput.RowCount);
                var matrixI = input.SelectColsView(cidListList[i]).ToShoMatrix(verbose: true);

                Parallel.For(i, cidListList.Count, ParallelOptionsScope.Current, j =>
                {
                    Console.WriteLine("Loading batch {0}, size {1}x{2}", j, cidListList[j].Count, unnormalizedInput.RowCount);

                    if (i == j)
                    {
                        ShoMatrix kii        = JustKernel(matrixI);
                        kernelPieces2D[i, i] = kii;
                    }
                    else
                    {
                        var matrixJ          = input.SelectColsView(cidListList[j]).ToShoMatrix(verbose: true);
                        ShoMatrix kij        = JustKernel(matrixI, matrixJ);
                        kernelPieces2D[i, j] = kij;
                        kernelPieces2D[j, i] = kij.TransposeView().ToShoMatrix();
                    }
                    counterWithMessages.Increment();
                });
            }
            counterWithMessages.Finished();


            var output = MatrixExtensions.MergeRowsAndColsView(kernelPieces2D);

            Helper.CheckCondition(output.RowKeys.SequenceEqual(output.ColKeys) && output.ColKeys.SequenceEqual(unnormalizedInput.ColKeys), "Assert: MergeRows isn't working as expected");

            KernelNormalizeInPlace(ref output);
            return(output);
        }