tomoto 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +123 -0
- data/ext/tomoto/ext.cpp +245 -0
- data/ext/tomoto/extconf.rb +28 -0
- data/lib/tomoto.rb +12 -0
- data/lib/tomoto/ct.rb +11 -0
- data/lib/tomoto/hdp.rb +11 -0
- data/lib/tomoto/lda.rb +67 -0
- data/lib/tomoto/version.rb +3 -0
- data/vendor/EigenRand/EigenRand/Core.h +1139 -0
- data/vendor/EigenRand/EigenRand/Dists/Basic.h +111 -0
- data/vendor/EigenRand/EigenRand/Dists/Discrete.h +877 -0
- data/vendor/EigenRand/EigenRand/Dists/GammaPoisson.h +108 -0
- data/vendor/EigenRand/EigenRand/Dists/NormalExp.h +626 -0
- data/vendor/EigenRand/EigenRand/EigenRand +19 -0
- data/vendor/EigenRand/EigenRand/Macro.h +24 -0
- data/vendor/EigenRand/EigenRand/MorePacketMath.h +978 -0
- data/vendor/EigenRand/EigenRand/PacketFilter.h +286 -0
- data/vendor/EigenRand/EigenRand/PacketRandomEngine.h +624 -0
- data/vendor/EigenRand/EigenRand/RandUtils.h +413 -0
- data/vendor/EigenRand/EigenRand/doc.h +220 -0
- data/vendor/EigenRand/LICENSE +21 -0
- data/vendor/EigenRand/README.md +288 -0
- data/vendor/eigen/COPYING.BSD +26 -0
- data/vendor/eigen/COPYING.GPL +674 -0
- data/vendor/eigen/COPYING.LGPL +502 -0
- data/vendor/eigen/COPYING.MINPACK +52 -0
- data/vendor/eigen/COPYING.MPL2 +373 -0
- data/vendor/eigen/COPYING.README +18 -0
- data/vendor/eigen/Eigen/CMakeLists.txt +19 -0
- data/vendor/eigen/Eigen/Cholesky +46 -0
- data/vendor/eigen/Eigen/CholmodSupport +48 -0
- data/vendor/eigen/Eigen/Core +537 -0
- data/vendor/eigen/Eigen/Dense +7 -0
- data/vendor/eigen/Eigen/Eigen +2 -0
- data/vendor/eigen/Eigen/Eigenvalues +61 -0
- data/vendor/eigen/Eigen/Geometry +62 -0
- data/vendor/eigen/Eigen/Householder +30 -0
- data/vendor/eigen/Eigen/IterativeLinearSolvers +48 -0
- data/vendor/eigen/Eigen/Jacobi +33 -0
- data/vendor/eigen/Eigen/LU +50 -0
- data/vendor/eigen/Eigen/MetisSupport +35 -0
- data/vendor/eigen/Eigen/OrderingMethods +73 -0
- data/vendor/eigen/Eigen/PaStiXSupport +48 -0
- data/vendor/eigen/Eigen/PardisoSupport +35 -0
- data/vendor/eigen/Eigen/QR +51 -0
- data/vendor/eigen/Eigen/QtAlignedMalloc +40 -0
- data/vendor/eigen/Eigen/SPQRSupport +34 -0
- data/vendor/eigen/Eigen/SVD +51 -0
- data/vendor/eigen/Eigen/Sparse +36 -0
- data/vendor/eigen/Eigen/SparseCholesky +45 -0
- data/vendor/eigen/Eigen/SparseCore +69 -0
- data/vendor/eigen/Eigen/SparseLU +46 -0
- data/vendor/eigen/Eigen/SparseQR +37 -0
- data/vendor/eigen/Eigen/StdDeque +27 -0
- data/vendor/eigen/Eigen/StdList +26 -0
- data/vendor/eigen/Eigen/StdVector +27 -0
- data/vendor/eigen/Eigen/SuperLUSupport +64 -0
- data/vendor/eigen/Eigen/UmfPackSupport +40 -0
- data/vendor/eigen/Eigen/src/Cholesky/LDLT.h +673 -0
- data/vendor/eigen/Eigen/src/Cholesky/LLT.h +542 -0
- data/vendor/eigen/Eigen/src/Cholesky/LLT_LAPACKE.h +99 -0
- data/vendor/eigen/Eigen/src/CholmodSupport/CholmodSupport.h +639 -0
- data/vendor/eigen/Eigen/src/Core/Array.h +329 -0
- data/vendor/eigen/Eigen/src/Core/ArrayBase.h +226 -0
- data/vendor/eigen/Eigen/src/Core/ArrayWrapper.h +209 -0
- data/vendor/eigen/Eigen/src/Core/Assign.h +90 -0
- data/vendor/eigen/Eigen/src/Core/AssignEvaluator.h +935 -0
- data/vendor/eigen/Eigen/src/Core/Assign_MKL.h +178 -0
- data/vendor/eigen/Eigen/src/Core/BandMatrix.h +353 -0
- data/vendor/eigen/Eigen/src/Core/Block.h +452 -0
- data/vendor/eigen/Eigen/src/Core/BooleanRedux.h +164 -0
- data/vendor/eigen/Eigen/src/Core/CommaInitializer.h +160 -0
- data/vendor/eigen/Eigen/src/Core/ConditionEstimator.h +175 -0
- data/vendor/eigen/Eigen/src/Core/CoreEvaluators.h +1688 -0
- data/vendor/eigen/Eigen/src/Core/CoreIterators.h +127 -0
- data/vendor/eigen/Eigen/src/Core/CwiseBinaryOp.h +184 -0
- data/vendor/eigen/Eigen/src/Core/CwiseNullaryOp.h +866 -0
- data/vendor/eigen/Eigen/src/Core/CwiseTernaryOp.h +197 -0
- data/vendor/eigen/Eigen/src/Core/CwiseUnaryOp.h +103 -0
- data/vendor/eigen/Eigen/src/Core/CwiseUnaryView.h +128 -0
- data/vendor/eigen/Eigen/src/Core/DenseBase.h +611 -0
- data/vendor/eigen/Eigen/src/Core/DenseCoeffsBase.h +681 -0
- data/vendor/eigen/Eigen/src/Core/DenseStorage.h +570 -0
- data/vendor/eigen/Eigen/src/Core/Diagonal.h +260 -0
- data/vendor/eigen/Eigen/src/Core/DiagonalMatrix.h +343 -0
- data/vendor/eigen/Eigen/src/Core/DiagonalProduct.h +28 -0
- data/vendor/eigen/Eigen/src/Core/Dot.h +318 -0
- data/vendor/eigen/Eigen/src/Core/EigenBase.h +159 -0
- data/vendor/eigen/Eigen/src/Core/ForceAlignedAccess.h +146 -0
- data/vendor/eigen/Eigen/src/Core/Fuzzy.h +155 -0
- data/vendor/eigen/Eigen/src/Core/GeneralProduct.h +455 -0
- data/vendor/eigen/Eigen/src/Core/GenericPacketMath.h +593 -0
- data/vendor/eigen/Eigen/src/Core/GlobalFunctions.h +187 -0
- data/vendor/eigen/Eigen/src/Core/IO.h +225 -0
- data/vendor/eigen/Eigen/src/Core/Inverse.h +118 -0
- data/vendor/eigen/Eigen/src/Core/Map.h +171 -0
- data/vendor/eigen/Eigen/src/Core/MapBase.h +303 -0
- data/vendor/eigen/Eigen/src/Core/MathFunctions.h +1415 -0
- data/vendor/eigen/Eigen/src/Core/MathFunctionsImpl.h +101 -0
- data/vendor/eigen/Eigen/src/Core/Matrix.h +459 -0
- data/vendor/eigen/Eigen/src/Core/MatrixBase.h +529 -0
- data/vendor/eigen/Eigen/src/Core/NestByValue.h +110 -0
- data/vendor/eigen/Eigen/src/Core/NoAlias.h +108 -0
- data/vendor/eigen/Eigen/src/Core/NumTraits.h +248 -0
- data/vendor/eigen/Eigen/src/Core/PermutationMatrix.h +633 -0
- data/vendor/eigen/Eigen/src/Core/PlainObjectBase.h +1035 -0
- data/vendor/eigen/Eigen/src/Core/Product.h +186 -0
- data/vendor/eigen/Eigen/src/Core/ProductEvaluators.h +1112 -0
- data/vendor/eigen/Eigen/src/Core/Random.h +182 -0
- data/vendor/eigen/Eigen/src/Core/Redux.h +505 -0
- data/vendor/eigen/Eigen/src/Core/Ref.h +283 -0
- data/vendor/eigen/Eigen/src/Core/Replicate.h +142 -0
- data/vendor/eigen/Eigen/src/Core/ReturnByValue.h +117 -0
- data/vendor/eigen/Eigen/src/Core/Reverse.h +211 -0
- data/vendor/eigen/Eigen/src/Core/Select.h +162 -0
- data/vendor/eigen/Eigen/src/Core/SelfAdjointView.h +352 -0
- data/vendor/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h +47 -0
- data/vendor/eigen/Eigen/src/Core/Solve.h +188 -0
- data/vendor/eigen/Eigen/src/Core/SolveTriangular.h +235 -0
- data/vendor/eigen/Eigen/src/Core/SolverBase.h +130 -0
- data/vendor/eigen/Eigen/src/Core/StableNorm.h +221 -0
- data/vendor/eigen/Eigen/src/Core/Stride.h +111 -0
- data/vendor/eigen/Eigen/src/Core/Swap.h +67 -0
- data/vendor/eigen/Eigen/src/Core/Transpose.h +403 -0
- data/vendor/eigen/Eigen/src/Core/Transpositions.h +407 -0
- data/vendor/eigen/Eigen/src/Core/TriangularMatrix.h +983 -0
- data/vendor/eigen/Eigen/src/Core/VectorBlock.h +96 -0
- data/vendor/eigen/Eigen/src/Core/VectorwiseOp.h +695 -0
- data/vendor/eigen/Eigen/src/Core/Visitor.h +273 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX/Complex.h +451 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h +439 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX/PacketMath.h +637 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h +51 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h +391 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h +1316 -0
- data/vendor/eigen/Eigen/src/Core/arch/AltiVec/Complex.h +430 -0
- data/vendor/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h +322 -0
- data/vendor/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h +1061 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/Complex.h +103 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/Half.h +674 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/MathFunctions.h +91 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/PacketMath.h +333 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/PacketMathHalf.h +1124 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/TypeCasting.h +212 -0
- data/vendor/eigen/Eigen/src/Core/arch/Default/ConjHelper.h +29 -0
- data/vendor/eigen/Eigen/src/Core/arch/Default/Settings.h +49 -0
- data/vendor/eigen/Eigen/src/Core/arch/NEON/Complex.h +490 -0
- data/vendor/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h +91 -0
- data/vendor/eigen/Eigen/src/Core/arch/NEON/PacketMath.h +760 -0
- data/vendor/eigen/Eigen/src/Core/arch/SSE/Complex.h +471 -0
- data/vendor/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h +562 -0
- data/vendor/eigen/Eigen/src/Core/arch/SSE/PacketMath.h +895 -0
- data/vendor/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h +77 -0
- data/vendor/eigen/Eigen/src/Core/arch/ZVector/Complex.h +397 -0
- data/vendor/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h +137 -0
- data/vendor/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h +945 -0
- data/vendor/eigen/Eigen/src/Core/functors/AssignmentFunctors.h +168 -0
- data/vendor/eigen/Eigen/src/Core/functors/BinaryFunctors.h +475 -0
- data/vendor/eigen/Eigen/src/Core/functors/NullaryFunctors.h +188 -0
- data/vendor/eigen/Eigen/src/Core/functors/StlFunctors.h +136 -0
- data/vendor/eigen/Eigen/src/Core/functors/TernaryFunctors.h +25 -0
- data/vendor/eigen/Eigen/src/Core/functors/UnaryFunctors.h +792 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h +2156 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h +492 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +311 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h +145 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h +122 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixVector.h +619 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h +136 -0
- data/vendor/eigen/Eigen/src/Core/products/Parallelizer.h +163 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +521 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h +287 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h +260 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h +118 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointProduct.h +133 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h +93 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h +466 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h +315 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixVector.h +350 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h +255 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h +335 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h +163 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularSolverVector.h +145 -0
- data/vendor/eigen/Eigen/src/Core/util/BlasUtil.h +398 -0
- data/vendor/eigen/Eigen/src/Core/util/Constants.h +547 -0
- data/vendor/eigen/Eigen/src/Core/util/DisableStupidWarnings.h +83 -0
- data/vendor/eigen/Eigen/src/Core/util/ForwardDeclarations.h +302 -0
- data/vendor/eigen/Eigen/src/Core/util/MKL_support.h +130 -0
- data/vendor/eigen/Eigen/src/Core/util/Macros.h +1001 -0
- data/vendor/eigen/Eigen/src/Core/util/Memory.h +993 -0
- data/vendor/eigen/Eigen/src/Core/util/Meta.h +534 -0
- data/vendor/eigen/Eigen/src/Core/util/NonMPL2.h +3 -0
- data/vendor/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h +27 -0
- data/vendor/eigen/Eigen/src/Core/util/StaticAssert.h +218 -0
- data/vendor/eigen/Eigen/src/Core/util/XprHelper.h +821 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/ComplexEigenSolver.h +346 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/ComplexSchur.h +459 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h +91 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/EigenSolver.h +622 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h +418 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h +226 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/HessenbergDecomposition.h +374 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h +158 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/RealQZ.h +654 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/RealSchur.h +546 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h +77 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h +870 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h +87 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/Tridiagonalization.h +556 -0
- data/vendor/eigen/Eigen/src/Geometry/AlignedBox.h +392 -0
- data/vendor/eigen/Eigen/src/Geometry/AngleAxis.h +247 -0
- data/vendor/eigen/Eigen/src/Geometry/EulerAngles.h +114 -0
- data/vendor/eigen/Eigen/src/Geometry/Homogeneous.h +497 -0
- data/vendor/eigen/Eigen/src/Geometry/Hyperplane.h +282 -0
- data/vendor/eigen/Eigen/src/Geometry/OrthoMethods.h +234 -0
- data/vendor/eigen/Eigen/src/Geometry/ParametrizedLine.h +195 -0
- data/vendor/eigen/Eigen/src/Geometry/Quaternion.h +814 -0
- data/vendor/eigen/Eigen/src/Geometry/Rotation2D.h +199 -0
- data/vendor/eigen/Eigen/src/Geometry/RotationBase.h +206 -0
- data/vendor/eigen/Eigen/src/Geometry/Scaling.h +170 -0
- data/vendor/eigen/Eigen/src/Geometry/Transform.h +1542 -0
- data/vendor/eigen/Eigen/src/Geometry/Translation.h +208 -0
- data/vendor/eigen/Eigen/src/Geometry/Umeyama.h +166 -0
- data/vendor/eigen/Eigen/src/Geometry/arch/Geometry_SSE.h +161 -0
- data/vendor/eigen/Eigen/src/Householder/BlockHouseholder.h +103 -0
- data/vendor/eigen/Eigen/src/Householder/Householder.h +172 -0
- data/vendor/eigen/Eigen/src/Householder/HouseholderSequence.h +470 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/BasicPreconditioners.h +226 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h +228 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h +246 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IncompleteCholesky.h +400 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h +462 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IterativeSolverBase.h +394 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/LeastSquareConjugateGradient.h +216 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/SolveWithGuess.h +115 -0
- data/vendor/eigen/Eigen/src/Jacobi/Jacobi.h +462 -0
- data/vendor/eigen/Eigen/src/LU/Determinant.h +101 -0
- data/vendor/eigen/Eigen/src/LU/FullPivLU.h +891 -0
- data/vendor/eigen/Eigen/src/LU/InverseImpl.h +415 -0
- data/vendor/eigen/Eigen/src/LU/PartialPivLU.h +611 -0
- data/vendor/eigen/Eigen/src/LU/PartialPivLU_LAPACKE.h +83 -0
- data/vendor/eigen/Eigen/src/LU/arch/Inverse_SSE.h +338 -0
- data/vendor/eigen/Eigen/src/MetisSupport/MetisSupport.h +137 -0
- data/vendor/eigen/Eigen/src/OrderingMethods/Amd.h +445 -0
- data/vendor/eigen/Eigen/src/OrderingMethods/Eigen_Colamd.h +1843 -0
- data/vendor/eigen/Eigen/src/OrderingMethods/Ordering.h +157 -0
- data/vendor/eigen/Eigen/src/PaStiXSupport/PaStiXSupport.h +678 -0
- data/vendor/eigen/Eigen/src/PardisoSupport/PardisoSupport.h +543 -0
- data/vendor/eigen/Eigen/src/QR/ColPivHouseholderQR.h +653 -0
- data/vendor/eigen/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h +97 -0
- data/vendor/eigen/Eigen/src/QR/CompleteOrthogonalDecomposition.h +562 -0
- data/vendor/eigen/Eigen/src/QR/FullPivHouseholderQR.h +676 -0
- data/vendor/eigen/Eigen/src/QR/HouseholderQR.h +409 -0
- data/vendor/eigen/Eigen/src/QR/HouseholderQR_LAPACKE.h +68 -0
- data/vendor/eigen/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h +313 -0
- data/vendor/eigen/Eigen/src/SVD/BDCSVD.h +1246 -0
- data/vendor/eigen/Eigen/src/SVD/JacobiSVD.h +804 -0
- data/vendor/eigen/Eigen/src/SVD/JacobiSVD_LAPACKE.h +91 -0
- data/vendor/eigen/Eigen/src/SVD/SVDBase.h +315 -0
- data/vendor/eigen/Eigen/src/SVD/UpperBidiagonalization.h +414 -0
- data/vendor/eigen/Eigen/src/SparseCholesky/SimplicialCholesky.h +689 -0
- data/vendor/eigen/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h +199 -0
- data/vendor/eigen/Eigen/src/SparseCore/AmbiVector.h +377 -0
- data/vendor/eigen/Eigen/src/SparseCore/CompressedStorage.h +258 -0
- data/vendor/eigen/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h +352 -0
- data/vendor/eigen/Eigen/src/SparseCore/MappedSparseMatrix.h +67 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseAssign.h +216 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseBlock.h +603 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseColEtree.h +206 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseCompressedBase.h +341 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseCwiseBinaryOp.h +726 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseCwiseUnaryOp.h +148 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseDenseProduct.h +320 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseDiagonalProduct.h +138 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseDot.h +98 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseFuzzy.h +29 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseMap.h +305 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseMatrix.h +1403 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseMatrixBase.h +405 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparsePermutation.h +178 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseProduct.h +169 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseRedux.h +49 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseRef.h +397 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseSelfAdjointView.h +656 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseSolverBase.h +124 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseSparseProductWithPruning.h +198 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseTranspose.h +92 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseTriangularView.h +189 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseUtil.h +178 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseVector.h +478 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseView.h +253 -0
- data/vendor/eigen/Eigen/src/SparseCore/TriangularSolver.h +315 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU.h +773 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLUImpl.h +66 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Memory.h +226 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Structs.h +110 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h +301 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Utils.h +80 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_column_bmod.h +181 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_column_dfs.h +179 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_copy_to_ucol.h +107 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_gemm_kernel.h +280 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_heap_relax_snode.h +126 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_kernel_bmod.h +130 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_panel_bmod.h +223 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_panel_dfs.h +258 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_pivotL.h +137 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_pruneL.h +136 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_relax_snode.h +83 -0
- data/vendor/eigen/Eigen/src/SparseQR/SparseQR.h +745 -0
- data/vendor/eigen/Eigen/src/StlSupport/StdDeque.h +126 -0
- data/vendor/eigen/Eigen/src/StlSupport/StdList.h +106 -0
- data/vendor/eigen/Eigen/src/StlSupport/StdVector.h +131 -0
- data/vendor/eigen/Eigen/src/StlSupport/details.h +84 -0
- data/vendor/eigen/Eigen/src/SuperLUSupport/SuperLUSupport.h +1027 -0
- data/vendor/eigen/Eigen/src/UmfPackSupport/UmfPackSupport.h +506 -0
- data/vendor/eigen/Eigen/src/misc/Image.h +82 -0
- data/vendor/eigen/Eigen/src/misc/Kernel.h +79 -0
- data/vendor/eigen/Eigen/src/misc/RealSvd2x2.h +55 -0
- data/vendor/eigen/Eigen/src/misc/blas.h +440 -0
- data/vendor/eigen/Eigen/src/misc/lapack.h +152 -0
- data/vendor/eigen/Eigen/src/misc/lapacke.h +16291 -0
- data/vendor/eigen/Eigen/src/misc/lapacke_mangling.h +17 -0
- data/vendor/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h +332 -0
- data/vendor/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h +552 -0
- data/vendor/eigen/Eigen/src/plugins/BlockMethods.h +1058 -0
- data/vendor/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h +115 -0
- data/vendor/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h +163 -0
- data/vendor/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h +152 -0
- data/vendor/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h +85 -0
- data/vendor/eigen/README.md +3 -0
- data/vendor/eigen/bench/README.txt +55 -0
- data/vendor/eigen/bench/btl/COPYING +340 -0
- data/vendor/eigen/bench/btl/README +154 -0
- data/vendor/eigen/bench/tensors/README +21 -0
- data/vendor/eigen/blas/README.txt +6 -0
- data/vendor/eigen/demos/mandelbrot/README +10 -0
- data/vendor/eigen/demos/mix_eigen_and_c/README +9 -0
- data/vendor/eigen/demos/opengl/README +13 -0
- data/vendor/eigen/unsupported/Eigen/CXX11/src/Tensor/README.md +1760 -0
- data/vendor/eigen/unsupported/README.txt +50 -0
- data/vendor/tomotopy/LICENSE +21 -0
- data/vendor/tomotopy/README.kr.rst +375 -0
- data/vendor/tomotopy/README.rst +382 -0
- data/vendor/tomotopy/src/Labeling/FoRelevance.cpp +362 -0
- data/vendor/tomotopy/src/Labeling/FoRelevance.h +88 -0
- data/vendor/tomotopy/src/Labeling/Labeler.h +50 -0
- data/vendor/tomotopy/src/TopicModel/CT.h +37 -0
- data/vendor/tomotopy/src/TopicModel/CTModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/CTModel.hpp +293 -0
- data/vendor/tomotopy/src/TopicModel/DMR.h +51 -0
- data/vendor/tomotopy/src/TopicModel/DMRModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/DMRModel.hpp +374 -0
- data/vendor/tomotopy/src/TopicModel/DT.h +65 -0
- data/vendor/tomotopy/src/TopicModel/DTM.h +22 -0
- data/vendor/tomotopy/src/TopicModel/DTModel.cpp +15 -0
- data/vendor/tomotopy/src/TopicModel/DTModel.hpp +572 -0
- data/vendor/tomotopy/src/TopicModel/GDMR.h +37 -0
- data/vendor/tomotopy/src/TopicModel/GDMRModel.cpp +14 -0
- data/vendor/tomotopy/src/TopicModel/GDMRModel.hpp +485 -0
- data/vendor/tomotopy/src/TopicModel/HDP.h +74 -0
- data/vendor/tomotopy/src/TopicModel/HDPModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/HDPModel.hpp +592 -0
- data/vendor/tomotopy/src/TopicModel/HLDA.h +40 -0
- data/vendor/tomotopy/src/TopicModel/HLDAModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/HLDAModel.hpp +681 -0
- data/vendor/tomotopy/src/TopicModel/HPA.h +27 -0
- data/vendor/tomotopy/src/TopicModel/HPAModel.cpp +21 -0
- data/vendor/tomotopy/src/TopicModel/HPAModel.hpp +588 -0
- data/vendor/tomotopy/src/TopicModel/LDA.h +144 -0
- data/vendor/tomotopy/src/TopicModel/LDACVB0Model.hpp +442 -0
- data/vendor/tomotopy/src/TopicModel/LDAModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/LDAModel.hpp +1058 -0
- data/vendor/tomotopy/src/TopicModel/LLDA.h +45 -0
- data/vendor/tomotopy/src/TopicModel/LLDAModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/LLDAModel.hpp +203 -0
- data/vendor/tomotopy/src/TopicModel/MGLDA.h +63 -0
- data/vendor/tomotopy/src/TopicModel/MGLDAModel.cpp +17 -0
- data/vendor/tomotopy/src/TopicModel/MGLDAModel.hpp +558 -0
- data/vendor/tomotopy/src/TopicModel/PA.h +43 -0
- data/vendor/tomotopy/src/TopicModel/PAModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/PAModel.hpp +467 -0
- data/vendor/tomotopy/src/TopicModel/PLDA.h +17 -0
- data/vendor/tomotopy/src/TopicModel/PLDAModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/PLDAModel.hpp +214 -0
- data/vendor/tomotopy/src/TopicModel/SLDA.h +54 -0
- data/vendor/tomotopy/src/TopicModel/SLDAModel.cpp +17 -0
- data/vendor/tomotopy/src/TopicModel/SLDAModel.hpp +456 -0
- data/vendor/tomotopy/src/TopicModel/TopicModel.hpp +692 -0
- data/vendor/tomotopy/src/Utils/AliasMethod.hpp +169 -0
- data/vendor/tomotopy/src/Utils/Dictionary.h +80 -0
- data/vendor/tomotopy/src/Utils/EigenAddonOps.hpp +181 -0
- data/vendor/tomotopy/src/Utils/LBFGS.h +202 -0
- data/vendor/tomotopy/src/Utils/LBFGS/LineSearchBacktracking.h +120 -0
- data/vendor/tomotopy/src/Utils/LBFGS/LineSearchBracketing.h +122 -0
- data/vendor/tomotopy/src/Utils/LBFGS/Param.h +213 -0
- data/vendor/tomotopy/src/Utils/LUT.hpp +82 -0
- data/vendor/tomotopy/src/Utils/MultiNormalDistribution.hpp +69 -0
- data/vendor/tomotopy/src/Utils/PolyaGamma.hpp +200 -0
- data/vendor/tomotopy/src/Utils/PolyaGammaHybrid.hpp +672 -0
- data/vendor/tomotopy/src/Utils/ThreadPool.hpp +150 -0
- data/vendor/tomotopy/src/Utils/Trie.hpp +220 -0
- data/vendor/tomotopy/src/Utils/TruncMultiNormal.hpp +94 -0
- data/vendor/tomotopy/src/Utils/Utils.hpp +337 -0
- data/vendor/tomotopy/src/Utils/avx_gamma.h +46 -0
- data/vendor/tomotopy/src/Utils/avx_mathfun.h +736 -0
- data/vendor/tomotopy/src/Utils/exception.h +28 -0
- data/vendor/tomotopy/src/Utils/math.h +281 -0
- data/vendor/tomotopy/src/Utils/rtnorm.hpp +2690 -0
- data/vendor/tomotopy/src/Utils/sample.hpp +192 -0
- data/vendor/tomotopy/src/Utils/serializer.hpp +695 -0
- data/vendor/tomotopy/src/Utils/slp.hpp +131 -0
- data/vendor/tomotopy/src/Utils/sse_gamma.h +48 -0
- data/vendor/tomotopy/src/Utils/sse_mathfun.h +710 -0
- data/vendor/tomotopy/src/Utils/text.hpp +49 -0
- data/vendor/tomotopy/src/Utils/tvector.hpp +543 -0
- metadata +531 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
#pragma once
|
2
|
+
#include "LDA.h"
|
3
|
+
|
4
|
+
namespace tomoto
|
5
|
+
{
|
6
|
+
template<TermWeight _tw>
|
7
|
+
struct DocumentPA : public DocumentLDA<_tw>
|
8
|
+
{
|
9
|
+
using BaseDocument = DocumentLDA<_tw>;
|
10
|
+
using DocumentLDA<_tw>::DocumentLDA;
|
11
|
+
using WeightType = typename DocumentLDA<_tw>::WeightType;
|
12
|
+
|
13
|
+
tvector<Tid> Z2s;
|
14
|
+
Eigen::Matrix<WeightType, -1, -1> numByTopic1_2;
|
15
|
+
|
16
|
+
template<typename _TopicModel> void update(WeightType* ptr, const _TopicModel& mdl);
|
17
|
+
|
18
|
+
DEFINE_SERIALIZER_AFTER_BASE_WITH_VERSION(BaseDocument, 0, Z2s);
|
19
|
+
DEFINE_TAGGED_SERIALIZER_AFTER_BASE_WITH_VERSION(BaseDocument, 1, 0x00010001, Z2s);
|
20
|
+
};
|
21
|
+
|
22
|
+
class IPAModel : public ILDAModel
|
23
|
+
{
|
24
|
+
public:
|
25
|
+
using DefaultDocType = DocumentPA<TermWeight::one>;
|
26
|
+
static IPAModel* create(TermWeight _weight, size_t _K1 = 1, size_t _K2 = 1,
|
27
|
+
Float _alpha = 0.1, Float _eta = 0.01, size_t seed = std::random_device{}(),
|
28
|
+
bool scalarRng = false);
|
29
|
+
|
30
|
+
virtual size_t getDirichletEstIteration() const = 0;
|
31
|
+
virtual void setDirichletEstIteration(size_t iter) = 0;
|
32
|
+
virtual size_t getK2() const = 0;
|
33
|
+
virtual Float getSubAlpha(Tid k1, Tid k2) const = 0;
|
34
|
+
virtual std::vector<Float> getSubAlpha(Tid k1) const = 0;
|
35
|
+
virtual std::vector<Float> getSubTopicBySuperTopic(Tid k) const = 0;
|
36
|
+
virtual std::vector<std::pair<Tid, Float>> getSubTopicBySuperTopicSorted(Tid k, size_t topN) const = 0;
|
37
|
+
|
38
|
+
virtual std::vector<Float> getSubTopicsByDoc(const DocumentBase* doc) const = 0;
|
39
|
+
virtual std::vector<std::pair<Tid, Float>> getSubTopicsByDocSorted(const DocumentBase* doc, size_t topN) const = 0;
|
40
|
+
|
41
|
+
virtual std::vector<uint64_t> getCountBySuperTopic() const = 0;
|
42
|
+
};
|
43
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#include "PAModel.hpp"
|
2
|
+
|
3
|
+
namespace tomoto
|
4
|
+
{
|
5
|
+
/*template class PAModel<TermWeight::one>;
|
6
|
+
template class PAModel<TermWeight::idf>;
|
7
|
+
template class PAModel<TermWeight::pmi>;*/
|
8
|
+
|
9
|
+
IPAModel* IPAModel::create(TermWeight _weight, size_t _K, size_t _K2, Float _alpha, Float _eta, size_t seed, bool scalarRng)
|
10
|
+
{
|
11
|
+
TMT_SWITCH_TW(_weight, scalarRng, PAModel, _K, _K2, _alpha, _eta, seed);
|
12
|
+
}
|
13
|
+
}
|
@@ -0,0 +1,467 @@
|
|
1
|
+
#pragma once
|
2
|
+
#include "LDAModel.hpp"
|
3
|
+
#include "PA.h"
|
4
|
+
|
5
|
+
/*
|
6
|
+
Implementation of Pachinko Allocation using Gibbs sampling by bab2min
|
7
|
+
|
8
|
+
Li, W., & McCallum, A. (2006, June). Pachinko allocation: DAG-structured mixture models of topic correlations. In Proceedings of the 23rd international conference on Machine learning (pp. 577-584). ACM.
|
9
|
+
*/
|
10
|
+
|
11
|
+
namespace tomoto
|
12
|
+
{
|
13
|
+
template<TermWeight _tw>
|
14
|
+
struct ModelStatePA : public ModelStateLDA<_tw>
|
15
|
+
{
|
16
|
+
using WeightType = typename ModelStateLDA<_tw>::WeightType;
|
17
|
+
Eigen::Matrix<WeightType, -1, -1> numByTopic1_2;
|
18
|
+
Eigen::Matrix<WeightType, -1, 1> numByTopic2;
|
19
|
+
Eigen::Matrix<Float, -1, 1> subTmp;
|
20
|
+
|
21
|
+
DEFINE_SERIALIZER_AFTER_BASE(ModelStateLDA<_tw>, numByTopic1_2, numByTopic2);
|
22
|
+
};
|
23
|
+
|
24
|
+
template<TermWeight _tw, typename _RandGen,
|
25
|
+
typename _Interface = IPAModel,
|
26
|
+
typename _Derived = void,
|
27
|
+
typename _DocType = DocumentPA<_tw>,
|
28
|
+
typename _ModelState = ModelStatePA<_tw>>
|
29
|
+
class PAModel : public LDAModel<_tw, _RandGen, 0, _Interface,
|
30
|
+
typename std::conditional<std::is_same<_Derived, void>::value, PAModel<_tw, _RandGen>, _Derived>::type,
|
31
|
+
_DocType, _ModelState>
|
32
|
+
{
|
33
|
+
protected:
|
34
|
+
using DerivedClass = typename std::conditional<std::is_same<_Derived, void>::value, PAModel<_tw, _RandGen>, _Derived>::type;
|
35
|
+
using BaseClass = LDAModel<_tw, _RandGen, 0, _Interface, DerivedClass, _DocType, _ModelState>;
|
36
|
+
friend BaseClass;
|
37
|
+
friend typename BaseClass::BaseClass;
|
38
|
+
using WeightType = typename BaseClass::WeightType;
|
39
|
+
|
40
|
+
Tid K2;
|
41
|
+
Float epsilon = 1e-5;
|
42
|
+
size_t iteration = 5;
|
43
|
+
|
44
|
+
Eigen::Matrix<Float, -1, 1> subAlphaSum; // len = K
|
45
|
+
Eigen::Matrix<Float, -1, -1> subAlphas; // len = K * K2
|
46
|
+
void optimizeParameters(ThreadPool& pool, _ModelState* localData, _RandGen* rgs)
|
47
|
+
{
|
48
|
+
const auto K = this->K;
|
49
|
+
std::vector<std::future<void>> res;
|
50
|
+
for (size_t k = 0; k < K; ++k)
|
51
|
+
{
|
52
|
+
res.emplace_back(pool.enqueue([&, k](size_t)
|
53
|
+
{
|
54
|
+
for (size_t i = 0; i < iteration; ++i)
|
55
|
+
{
|
56
|
+
Float denom = this->template calcDigammaSum<>(nullptr, [&](size_t i) { return this->docs[i].numByTopic[k]; }, this->docs.size(), subAlphaSum[k]);
|
57
|
+
for (size_t k2 = 0; k2 < K2; ++k2)
|
58
|
+
{
|
59
|
+
Float nom = this->template calcDigammaSum<>(nullptr, [&](size_t i) { return this->docs[i].numByTopic1_2(k, k2); }, this->docs.size(), subAlphas(k, k2));
|
60
|
+
subAlphas(k, k2) = std::max(nom / denom * subAlphas(k, k2), epsilon);
|
61
|
+
}
|
62
|
+
subAlphaSum[k] = subAlphas.row(k).sum();
|
63
|
+
}
|
64
|
+
}));
|
65
|
+
}
|
66
|
+
for (auto& r : res) r.get();
|
67
|
+
}
|
68
|
+
|
69
|
+
// topic 1 & 2 assignment likelihoods for new word. ret K*K2 FLOATs
|
70
|
+
template<bool _asymEta>
|
71
|
+
Float* getZLikelihoods(_ModelState& ld, const _DocType& doc, size_t docId, size_t vid) const
|
72
|
+
{
|
73
|
+
const size_t V = this->realV;
|
74
|
+
const auto eta = this->eta;
|
75
|
+
assert(vid < V);
|
76
|
+
auto etaHelper = this->template getEtaHelper<_asymEta>();
|
77
|
+
auto& zLikelihood = ld.zLikelihood;
|
78
|
+
|
79
|
+
ld.subTmp = (ld.numByTopicWord.col(vid).array().template cast<Float>() + etaHelper.getEta(vid))
|
80
|
+
/ (ld.numByTopic2.array().template cast<Float>() + etaHelper.getEtaSum());
|
81
|
+
|
82
|
+
for (size_t k = 0; k < this->K; ++k)
|
83
|
+
{
|
84
|
+
zLikelihood.segment(K2 * k, K2) = (doc.numByTopic[k] + this->alpha)
|
85
|
+
* (doc.numByTopic1_2.row(k).transpose().array().template cast<Float>() + subAlphas.row(k).transpose().array()) / (doc.numByTopic[k] + subAlphaSum[k])
|
86
|
+
* ld.subTmp.array();
|
87
|
+
}
|
88
|
+
sample::prefixSum(zLikelihood.data(), zLikelihood.size());
|
89
|
+
return &zLikelihood[0];
|
90
|
+
}
|
91
|
+
|
92
|
+
template<int _inc>
|
93
|
+
inline void addWordTo(_ModelState& ld, _DocType& doc, uint32_t pid, Vid vid, Tid z1, Tid z2) const
|
94
|
+
{
|
95
|
+
assert(vid < this->realV);
|
96
|
+
constexpr bool _dec = _inc < 0 && _tw != TermWeight::one;
|
97
|
+
typename std::conditional<_tw != TermWeight::one, float, int32_t>::type weight
|
98
|
+
= _tw != TermWeight::one ? doc.wordWeights[pid] : 1;
|
99
|
+
|
100
|
+
updateCnt<_dec>(doc.numByTopic[z1], _inc * weight);
|
101
|
+
updateCnt<_dec>(doc.numByTopic1_2(z1, z2), _inc * weight);
|
102
|
+
updateCnt<_dec>(ld.numByTopic[z1], _inc * weight);
|
103
|
+
updateCnt<_dec>(ld.numByTopic2[z2], _inc * weight);
|
104
|
+
updateCnt<_dec>(ld.numByTopic1_2(z1, z2), _inc * weight);
|
105
|
+
updateCnt<_dec>(ld.numByTopicWord(z2, vid), _inc * weight);
|
106
|
+
}
|
107
|
+
|
108
|
+
template<ParallelScheme _ps, bool _infer, typename _ExtraDocData>
|
109
|
+
void sampleDocument(_DocType& doc, const _ExtraDocData& edd, size_t docId, _ModelState& ld, _RandGen& rgs, size_t iterationCnt, size_t partitionId = 0) const
|
110
|
+
{
|
111
|
+
size_t b = 0, e = doc.words.size();
|
112
|
+
if (_ps == ParallelScheme::partition)
|
113
|
+
{
|
114
|
+
b = edd.chunkOffsetByDoc(partitionId, docId);
|
115
|
+
e = edd.chunkOffsetByDoc(partitionId + 1, docId);
|
116
|
+
}
|
117
|
+
|
118
|
+
size_t vOffset = (_ps == ParallelScheme::partition && partitionId) ? edd.vChunkOffset[partitionId - 1] : 0;
|
119
|
+
for (size_t w = b; w < e; ++w)
|
120
|
+
{
|
121
|
+
if (doc.words[w] >= this->realV) continue;
|
122
|
+
addWordTo<-1>(ld, doc, w, doc.words[w] - vOffset, doc.Zs[w], doc.Z2s[w]);
|
123
|
+
Float* dist;
|
124
|
+
if (this->etaByTopicWord.size())
|
125
|
+
{
|
126
|
+
dist = getZLikelihoods<true>(ld, doc, docId, doc.words[w] - vOffset);
|
127
|
+
}
|
128
|
+
else
|
129
|
+
{
|
130
|
+
dist = getZLikelihoods<false>(ld, doc, docId, doc.words[w] - vOffset);
|
131
|
+
}
|
132
|
+
auto z = sample::sampleFromDiscreteAcc(dist, dist + this->K * K2, rgs);
|
133
|
+
doc.Zs[w] = z / K2;
|
134
|
+
doc.Z2s[w] = z % K2;
|
135
|
+
addWordTo<1>(ld, doc, w, doc.words[w] - vOffset, doc.Zs[w], doc.Z2s[w]);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
template<typename _ExtraDocData>
|
140
|
+
void distributePartition(ThreadPool& pool, const _ModelState& globalState, _ModelState* localData, const _ExtraDocData& edd) const
|
141
|
+
{
|
142
|
+
std::vector<std::future<void>> res = pool.enqueueToAll([&](size_t partitionId)
|
143
|
+
{
|
144
|
+
size_t b = partitionId ? edd.vChunkOffset[partitionId - 1] : 0,
|
145
|
+
e = edd.vChunkOffset[partitionId];
|
146
|
+
|
147
|
+
localData[partitionId].numByTopicWord = globalState.numByTopicWord.block(0, b, globalState.numByTopicWord.rows(), e - b);
|
148
|
+
localData[partitionId].numByTopic = globalState.numByTopic;
|
149
|
+
localData[partitionId].numByTopic1_2 = globalState.numByTopic1_2;
|
150
|
+
localData[partitionId].numByTopic2 = globalState.numByTopic2;
|
151
|
+
if (!localData[partitionId].zLikelihood.size()) localData[partitionId].zLikelihood = globalState.zLikelihood;
|
152
|
+
});
|
153
|
+
|
154
|
+
for (auto& r : res) r.get();
|
155
|
+
}
|
156
|
+
|
157
|
+
template<ParallelScheme _ps, typename _ExtraDocData>
|
158
|
+
void mergeState(ThreadPool& pool, _ModelState& globalState, _ModelState& tState, _ModelState* localData, _RandGen*, const _ExtraDocData& edd) const
|
159
|
+
{
|
160
|
+
std::vector<std::future<void>> res;
|
161
|
+
|
162
|
+
if (_ps == ParallelScheme::copy_merge)
|
163
|
+
{
|
164
|
+
tState = globalState;
|
165
|
+
globalState = localData[0];
|
166
|
+
for (size_t i = 1; i < pool.getNumWorkers(); ++i)
|
167
|
+
{
|
168
|
+
globalState.numByTopic += localData[i].numByTopic - tState.numByTopic;
|
169
|
+
globalState.numByTopic1_2 += localData[i].numByTopic1_2 - tState.numByTopic1_2;
|
170
|
+
globalState.numByTopic2 += localData[i].numByTopic2 - tState.numByTopic2;
|
171
|
+
globalState.numByTopicWord += localData[i].numByTopicWord - tState.numByTopicWord;
|
172
|
+
}
|
173
|
+
|
174
|
+
// make all count being positive
|
175
|
+
if (_tw != TermWeight::one)
|
176
|
+
{
|
177
|
+
globalState.numByTopic = globalState.numByTopic.cwiseMax(0);
|
178
|
+
globalState.numByTopic1_2 = globalState.numByTopic1_2.cwiseMax(0);
|
179
|
+
globalState.numByTopic2 = globalState.numByTopic2.cwiseMax(0);
|
180
|
+
globalState.numByTopicWord = globalState.numByTopicWord.cwiseMax(0);
|
181
|
+
}
|
182
|
+
|
183
|
+
for (size_t i = 0; i < pool.getNumWorkers(); ++i)
|
184
|
+
{
|
185
|
+
res.emplace_back(pool.enqueue([&, this, i](size_t threadId)
|
186
|
+
{
|
187
|
+
localData[i] = globalState;
|
188
|
+
}));
|
189
|
+
}
|
190
|
+
}
|
191
|
+
else if (_ps == ParallelScheme::partition)
|
192
|
+
{
|
193
|
+
res = pool.enqueueToAll([&](size_t partitionId)
|
194
|
+
{
|
195
|
+
size_t b = partitionId ? edd.vChunkOffset[partitionId - 1] : 0,
|
196
|
+
e = edd.vChunkOffset[partitionId];
|
197
|
+
globalState.numByTopicWord.block(0, b, globalState.numByTopicWord.rows(), e - b) = localData[partitionId].numByTopicWord;
|
198
|
+
});
|
199
|
+
for (auto& r : res) r.get();
|
200
|
+
res.clear();
|
201
|
+
|
202
|
+
tState.numByTopic1_2 = globalState.numByTopic1_2;
|
203
|
+
globalState.numByTopic1_2 = localData[0].numByTopic1_2;
|
204
|
+
for (size_t i = 1; i < pool.getNumWorkers(); ++i)
|
205
|
+
{
|
206
|
+
globalState.numByTopic1_2 += localData[i].numByTopic1_2 - tState.numByTopic1_2;
|
207
|
+
}
|
208
|
+
|
209
|
+
// make all count being positive
|
210
|
+
if (_tw != TermWeight::one)
|
211
|
+
{
|
212
|
+
globalState.numByTopicWord = globalState.numByTopicWord.cwiseMax(0);
|
213
|
+
}
|
214
|
+
globalState.numByTopic = globalState.numByTopic1_2.rowwise().sum();
|
215
|
+
globalState.numByTopic2 = globalState.numByTopicWord.rowwise().sum();
|
216
|
+
|
217
|
+
res = pool.enqueueToAll([&](size_t threadId)
|
218
|
+
{
|
219
|
+
localData[threadId].numByTopic = globalState.numByTopic;
|
220
|
+
localData[threadId].numByTopic1_2 = globalState.numByTopic1_2;
|
221
|
+
localData[threadId].numByTopic2 = globalState.numByTopic2;
|
222
|
+
});
|
223
|
+
}
|
224
|
+
|
225
|
+
for (auto& r : res) r.get();
|
226
|
+
}
|
227
|
+
|
228
|
+
template<typename _DocIter>
|
229
|
+
double getLLDocs(_DocIter _first, _DocIter _last) const
|
230
|
+
{
|
231
|
+
const auto K = this->K;
|
232
|
+
const auto alpha = this->alpha;
|
233
|
+
float ll = (math::lgammaT(K*alpha) - math::lgammaT(alpha)*K) * std::distance(_first, _last);
|
234
|
+
for (; _first != _last; ++_first)
|
235
|
+
{
|
236
|
+
auto& doc = *_first;
|
237
|
+
ll -= math::lgammaT(doc.getSumWordWeight() + K * alpha);
|
238
|
+
for (Tid k = 0; k < K; ++k)
|
239
|
+
{
|
240
|
+
ll += math::lgammaT(doc.numByTopic[k] + alpha);
|
241
|
+
}
|
242
|
+
}
|
243
|
+
return ll;
|
244
|
+
}
|
245
|
+
|
246
|
+
double getLLRest(const _ModelState& ld) const
|
247
|
+
{
|
248
|
+
const size_t V = this->realV;
|
249
|
+
const auto K = this->K;
|
250
|
+
const auto eta = this->eta;
|
251
|
+
|
252
|
+
double ll = 0;
|
253
|
+
for (Tid k = 0; k < K; ++k)
|
254
|
+
{
|
255
|
+
ll += math::lgammaT(subAlphaSum[k]);
|
256
|
+
ll -= math::lgammaT(ld.numByTopic[k] + subAlphaSum[k]);
|
257
|
+
for (Tid k2 = 0; k2 < K2; ++k2)
|
258
|
+
{
|
259
|
+
ll -= math::lgammaT(subAlphas(k, k2));
|
260
|
+
ll += math::lgammaT(ld.numByTopic1_2(k, k2) + subAlphas(k, k2));
|
261
|
+
}
|
262
|
+
}
|
263
|
+
ll += (math::lgammaT(V*eta) - math::lgammaT(eta)*V) * K2;
|
264
|
+
for (Tid k2 = 0; k2 < K2; ++k2)
|
265
|
+
{
|
266
|
+
ll -= math::lgammaT(ld.numByTopic2[k2] + V * eta);
|
267
|
+
for (Vid v = 0; v < V; ++v)
|
268
|
+
{
|
269
|
+
ll += math::lgammaT(ld.numByTopicWord(k2, v) + eta);
|
270
|
+
}
|
271
|
+
}
|
272
|
+
return ll;
|
273
|
+
}
|
274
|
+
|
275
|
+
void prepareDoc(_DocType& doc, size_t docId, size_t wordSize) const
|
276
|
+
{
|
277
|
+
BaseClass::prepareDoc(doc, docId, wordSize);
|
278
|
+
|
279
|
+
doc.numByTopic1_2 = Eigen::Matrix<WeightType, -1, -1>::Zero(this->K, K2);
|
280
|
+
doc.Z2s = tvector<Tid>(wordSize);
|
281
|
+
}
|
282
|
+
|
283
|
+
void prepareWordPriors()
|
284
|
+
{
|
285
|
+
if (this->etaByWord.empty()) return;
|
286
|
+
this->etaByTopicWord.resize(K2, this->realV);
|
287
|
+
this->etaSumByTopic.resize(K2);
|
288
|
+
this->etaByTopicWord.array() = this->eta;
|
289
|
+
for (auto& it : this->etaByWord)
|
290
|
+
{
|
291
|
+
auto id = this->dict.toWid(it.first);
|
292
|
+
if (id == (Vid)-1 || id >= this->realV) continue;
|
293
|
+
this->etaByTopicWord.col(id) = Eigen::Map<Eigen::Matrix<Float, -1, 1>>{ it.second.data(), (Eigen::Index)it.second.size() };
|
294
|
+
}
|
295
|
+
this->etaSumByTopic = this->etaByTopicWord.rowwise().sum();
|
296
|
+
}
|
297
|
+
|
298
|
+
void initGlobalState(bool initDocs)
|
299
|
+
{
|
300
|
+
const size_t V = this->realV;
|
301
|
+
this->globalState.zLikelihood = Eigen::Matrix<Float, -1, 1>::Zero(this->K * K2);
|
302
|
+
if (initDocs)
|
303
|
+
{
|
304
|
+
this->globalState.numByTopic = Eigen::Matrix<WeightType, -1, 1>::Zero(this->K);
|
305
|
+
this->globalState.numByTopic2 = Eigen::Matrix<WeightType, -1, 1>::Zero(K2);
|
306
|
+
this->globalState.numByTopic1_2 = Eigen::Matrix<WeightType, -1, -1>::Zero(this->K, K2);
|
307
|
+
this->globalState.numByTopicWord = Eigen::Matrix<WeightType, -1, -1>::Zero(K2, V);
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
struct Generator
|
312
|
+
{
|
313
|
+
std::uniform_int_distribution<Tid> theta, theta2;
|
314
|
+
};
|
315
|
+
|
316
|
+
Generator makeGeneratorForInit(const _DocType*) const
|
317
|
+
{
|
318
|
+
return Generator{
|
319
|
+
std::uniform_int_distribution<Tid>{0, (Tid)(this->K - 1)},
|
320
|
+
std::uniform_int_distribution<Tid>{0, (Tid)(K2 - 1)},
|
321
|
+
};
|
322
|
+
}
|
323
|
+
|
324
|
+
template<bool _Infer>
|
325
|
+
void updateStateWithDoc(Generator& g, _ModelState& ld, _RandGen& rgs, _DocType& doc, size_t i) const
|
326
|
+
{
|
327
|
+
auto w = doc.words[i];
|
328
|
+
doc.Zs[i] = g.theta(rgs);
|
329
|
+
if (this->etaByTopicWord.size())
|
330
|
+
{
|
331
|
+
auto col = this->etaByTopicWord.col(w);
|
332
|
+
doc.Z2s[i] = sample::sampleFromDiscrete(col.data(), col.data() + col.size(), rgs);
|
333
|
+
}
|
334
|
+
else
|
335
|
+
{
|
336
|
+
doc.Z2s[i] = g.theta2(rgs);
|
337
|
+
}
|
338
|
+
addWordTo<1>(ld, doc, i, w, doc.Zs[i], doc.Z2s[i]);
|
339
|
+
}
|
340
|
+
|
341
|
+
std::vector<uint64_t> _getTopicsCount() const
|
342
|
+
{
|
343
|
+
std::vector<uint64_t> cnt(this->K2);
|
344
|
+
for (auto& doc : this->docs)
|
345
|
+
{
|
346
|
+
for (size_t i = 0; i < doc.Z2s.size(); ++i)
|
347
|
+
{
|
348
|
+
if (doc.words[i] < this->realV) ++cnt[doc.Z2s[i]];
|
349
|
+
}
|
350
|
+
}
|
351
|
+
return cnt;
|
352
|
+
}
|
353
|
+
|
354
|
+
public:
|
355
|
+
DEFINE_SERIALIZER_AFTER_BASE_WITH_VERSION(BaseClass, 0, K2, subAlphas, subAlphaSum);
|
356
|
+
DEFINE_TAGGED_SERIALIZER_AFTER_BASE_WITH_VERSION(BaseClass, 1, 0x00010001, K2, subAlphas, subAlphaSum);
|
357
|
+
|
358
|
+
PAModel(size_t _K1 = 1, size_t _K2 = 1, Float _alpha = 0.1, Float _eta = 0.01, size_t _rg = std::random_device{}())
|
359
|
+
: BaseClass(_K1, _alpha, _eta, _rg), K2(_K2)
|
360
|
+
{
|
361
|
+
if (_K2 == 0 || _K2 >= 0x80000000) THROW_ERROR_WITH_INFO(std::runtime_error, text::format("wrong K2 value (K2 = %zd)", _K2));
|
362
|
+
subAlphaSum = Eigen::Matrix<Float, -1, 1>::Constant(_K1, _K2 * 0.1);
|
363
|
+
subAlphas = Eigen::Matrix<Float, -1, -1>::Constant(_K1, _K2, 0.1);
|
364
|
+
this->optimInterval = 1;
|
365
|
+
}
|
366
|
+
|
367
|
+
GETTER(K2, size_t, K2);
|
368
|
+
GETTER(DirichletEstIteration, size_t, iteration);
|
369
|
+
|
370
|
+
void setDirichletEstIteration(size_t iter) override
|
371
|
+
{
|
372
|
+
if (!iter) throw std::invalid_argument("iter must > 0");
|
373
|
+
iteration = iter;
|
374
|
+
}
|
375
|
+
|
376
|
+
Float getSubAlpha(Tid k1, Tid k2) const override { return subAlphas(k1, k2); }
|
377
|
+
|
378
|
+
std::vector<Float> getSubAlpha(Tid k1) const override
|
379
|
+
{
|
380
|
+
std::vector<Float> ret(K2);
|
381
|
+
Eigen::Map<Eigen::VectorXf>{ret.data(), (Eigen::Index)ret.size()} = subAlphas.row(k1).transpose();
|
382
|
+
return ret;
|
383
|
+
}
|
384
|
+
|
385
|
+
std::vector<Float> getSubTopicBySuperTopic(Tid k) const override
|
386
|
+
{
|
387
|
+
assert(k < this->K);
|
388
|
+
Float sum = this->globalState.numByTopic[k] + subAlphaSum[k];
|
389
|
+
Eigen::Matrix<Float, -1, 1> ret = (this->globalState.numByTopic1_2.row(k).array().template cast<Float>() + subAlphas.row(k).array()) / sum;
|
390
|
+
return { ret.data(), ret.data() + K2 };
|
391
|
+
}
|
392
|
+
|
393
|
+
std::vector<std::pair<Tid, Float>> getSubTopicBySuperTopicSorted(Tid k, size_t topN) const override
|
394
|
+
{
|
395
|
+
return extractTopN<Tid>(getSubTopicBySuperTopic(k), topN);
|
396
|
+
}
|
397
|
+
|
398
|
+
std::vector<Float> getSubTopicsByDoc(const _DocType& doc) const
|
399
|
+
{
|
400
|
+
std::vector<Float> ret(K2);
|
401
|
+
Eigen::Map<Eigen::Matrix<Float, -1, 1>> { ret.data(), K2 }.array() =
|
402
|
+
((doc.numByTopic1_2.array().template cast<Float>() + subAlphas.array()).colwise().sum()) / (doc.getSumWordWeight() + subAlphas.sum());
|
403
|
+
return ret;
|
404
|
+
}
|
405
|
+
|
406
|
+
std::vector<Float> getSubTopicsByDoc(const DocumentBase* doc) const override
|
407
|
+
{
|
408
|
+
return static_cast<const DerivedClass*>(this)->getSubTopicsByDoc(*static_cast<const _DocType*>(doc));
|
409
|
+
}
|
410
|
+
|
411
|
+
std::vector<std::pair<Tid, Float>> getSubTopicsByDocSorted(const DocumentBase* doc, size_t topN) const override
|
412
|
+
{
|
413
|
+
return extractTopN<Tid>(getSubTopicsByDoc(doc), topN);
|
414
|
+
}
|
415
|
+
|
416
|
+
std::vector<Float> _getWidsByTopic(Tid k2) const
|
417
|
+
{
|
418
|
+
assert(k2 < K2);
|
419
|
+
const size_t V = this->realV;
|
420
|
+
std::vector<Float> ret(V);
|
421
|
+
Float sum = this->globalState.numByTopic2[k2] + V * this->eta;
|
422
|
+
auto r = this->globalState.numByTopicWord.row(k2);
|
423
|
+
for (size_t v = 0; v < V; ++v)
|
424
|
+
{
|
425
|
+
ret[v] = (r[v] + this->eta) / sum;
|
426
|
+
}
|
427
|
+
return ret;
|
428
|
+
}
|
429
|
+
|
430
|
+
void setWordPrior(const std::string& word, const std::vector<Float>& priors) override
|
431
|
+
{
|
432
|
+
if (priors.size() != K2) THROW_ERROR_WITH_INFO(exception::InvalidArgument, "priors.size() must be equal to K2.");
|
433
|
+
for (auto p : priors)
|
434
|
+
{
|
435
|
+
if (p < 0) THROW_ERROR_WITH_INFO(exception::InvalidArgument, "priors must not be less than 0.");
|
436
|
+
}
|
437
|
+
this->dict.add(word);
|
438
|
+
this->etaByWord.emplace(word, priors);
|
439
|
+
}
|
440
|
+
|
441
|
+
std::vector<uint64_t> getCountBySuperTopic() const override
|
442
|
+
{
|
443
|
+
std::vector<uint64_t> cnt(this->K);
|
444
|
+
for (auto& doc : this->docs)
|
445
|
+
{
|
446
|
+
for (size_t i = 0; i < doc.Zs.size(); ++i)
|
447
|
+
{
|
448
|
+
if (doc.words[i] < this->realV) ++cnt[doc.Zs[i]];
|
449
|
+
}
|
450
|
+
}
|
451
|
+
return cnt;
|
452
|
+
}
|
453
|
+
};
|
454
|
+
|
455
|
+
template<TermWeight _tw>
|
456
|
+
template<typename _TopicModel>
|
457
|
+
void DocumentPA<_tw>::update(WeightType * ptr, const _TopicModel & mdl)
|
458
|
+
{
|
459
|
+
DocumentLDA<_tw>::update(ptr, mdl);
|
460
|
+
numByTopic1_2 = Eigen::Matrix<WeightType, -1, -1>::Zero(mdl.getK(), mdl.getK2());
|
461
|
+
for (size_t i = 0; i < this->Zs.size(); ++i)
|
462
|
+
{
|
463
|
+
if (this->words[i] >= mdl.getV()) continue;
|
464
|
+
numByTopic1_2(this->Zs[i], Z2s[i]) += _tw != TermWeight::one ? this->wordWeights[i] : 1;
|
465
|
+
}
|
466
|
+
}
|
467
|
+
}
|