void lle(GArgReader& args) { // Load the file and params GMatrix* pData = loadData(args.pop_string()); Holder<GMatrix> hData(pData); unsigned int nSeed = getpid() * (unsigned int)time(NULL); GRand prng(nSeed); GNeighborFinder* pNF = instantiateNeighborFinder(pData, &prng, args); Holder<GNeighborFinder> hNF(pNF); int targetDims = args.pop_uint(); // Parse Options while(args.size() > 0) { if(args.if_pop("-seed")) prng.setSeed(args.pop_uint()); else throw Ex("Invalid option: ", args.peek()); } // Transform the data GLLE transform(pNF->neighborCount(), targetDims, &prng); transform.setNeighborFinder(pNF); GMatrix* pDataAfter = transform.doit(*pData); Holder<GMatrix> hDataAfter(pDataAfter); pDataAfter->print(cout); }
void isomap(GArgReader& args) { // Load the file and params GMatrix* pData = loadData(args.pop_string()); Holder<GMatrix> hData(pData); unsigned int nSeed = getpid() * (unsigned int)time(NULL); GRand prng(nSeed); GNeighborFinder* pNF = instantiateNeighborFinder(pData, &prng, args); Holder<GNeighborFinder> hNF(pNF); int targetDims = args.pop_uint(); // Parse Options bool tolerant = false; while(args.size() > 0) { if(args.if_pop("-seed")) prng.setSeed(args.pop_uint()); else if(args.if_pop("-tolerant")) tolerant = true; else throw Ex("Invalid option: ", args.peek()); } // Transform the data GIsomap transform(pNF->neighborCount(), targetDims, &prng); transform.setNeighborFinder(pNF); if(tolerant) transform.dropDisconnectedPoints(); GMatrix* pDataAfter = transform.reduce(*pData); Holder<GMatrix> hDataAfter(pDataAfter); pDataAfter->print(cout); }
void breadthFirstUnfolding(GArgReader& args) { // Load the file and params GMatrix* pData = loadData(args.pop_string()); Holder<GMatrix> hData(pData); size_t nSeed = getpid() * (unsigned int)time(NULL); GRand prng(nSeed); GNeighborFinder* pNF = instantiateNeighborFinder(pData, &prng, args); Holder<GNeighborFinder> hNF(pNF); int targetDims = args.pop_uint(); // Parse Options size_t reps = 1; Holder<GMatrix> hControlData(NULL); while(args.size() > 0) { if(args.if_pop("-seed")) nSeed = args.pop_uint(); else if(args.if_pop("-reps")) reps = args.pop_uint(); else throw Ex("Invalid option: ", args.peek()); } // Transform the data GBreadthFirstUnfolding transform(reps, pNF->neighborCount(), targetDims); transform.rand().setSeed(nSeed); transform.setNeighborFinder(pNF); GMatrix* pDataAfter = transform.reduce(*pData); Holder<GMatrix> hDataAfter(pDataAfter); pDataAfter->print(cout); }
void ManifoldSculpting(GArgReader& args) { // Load the file and params GMatrix* pData = loadData(args.pop_string()); Holder<GMatrix> hData(pData); unsigned int nSeed = getpid() * (unsigned int)time(NULL); GRand prng(nSeed); GNeighborFinder* pNF = instantiateNeighborFinder(pData, &prng, args); Holder<GNeighborFinder> hNF(pNF); size_t targetDims = args.pop_uint(); // Parse Options const char* szPreprocessedData = NULL; double scaleRate = 0.999; while(args.size() > 0) { if(args.if_pop("-seed")) prng.setSeed(args.pop_uint()); else if(args.if_pop("-continue")) szPreprocessedData = args.pop_string(); else if(args.if_pop("-scalerate")) scaleRate = args.pop_double(); else throw Ex("Invalid option: ", args.peek()); } // Load the hint data GMatrix* pDataHint = NULL; Holder<GMatrix> hDataHint(NULL); if(szPreprocessedData) { pDataHint = loadData(szPreprocessedData); hDataHint.reset(pDataHint); if(pDataHint->relation()->size() != targetDims) throw Ex("Wrong number of dims in the hint data"); if(pDataHint->rows() != pData->rows()) throw Ex("Wrong number of patterns in the hint data"); } // Transform the data GManifoldSculpting transform(pNF->neighborCount(), targetDims, &prng); transform.setSquishingRate(scaleRate); if(pDataHint) transform.setPreprocessedData(hDataHint.release()); transform.setNeighborFinder(pNF); GMatrix* pDataAfter = transform.doit(*pData); Holder<GMatrix> hDataAfter(pDataAfter); pDataAfter->print(cout); }
void blendEmbeddings(GArgReader& args) { // Load the files and params GMatrix* pDataOrig = loadData(args.pop_string()); Holder<GMatrix> hDataOrig(pDataOrig); unsigned int seed = getpid() * (unsigned int)time(NULL); GRand prng(seed); GNeighborFinder* pNF = instantiateNeighborFinder(pDataOrig, &prng, args); Holder<GNeighborFinder> hNF(pNF); GMatrix* pDataA = loadData(args.pop_string()); Holder<GMatrix> hDataA(pDataA); GMatrix* pDataB = loadData(args.pop_string()); Holder<GMatrix> hDataB(pDataB); if(pDataA->rows() != pDataOrig->rows() || pDataB->rows() != pDataOrig->rows()) throw Ex("mismatching number of rows"); if(pDataA->cols() != pDataB->cols()) throw Ex("mismatching number of cols"); // Parse Options while(args.size() > 0) { if(args.if_pop("-seed")) prng.setSeed(args.pop_uint()); else throw Ex("Invalid option: ", args.peek()); } // Get a neighbor table if(!pNF->isCached()) { GNeighborFinderCacheWrapper* pNF2 = new GNeighborFinderCacheWrapper(hNF.release(), true); hNF.reset(pNF2); pNF = pNF2; } ((GNeighborFinderCacheWrapper*)pNF)->fillCache(); size_t* pNeighborTable = ((GNeighborFinderCacheWrapper*)pNF)->cache(); // Do the blending size_t startPoint = (size_t)prng.next(pDataA->rows()); double* pRatios = new double[pDataA->rows()]; ArrayHolder<double> hRatios(pRatios); GVec::setAll(pRatios, 0.5, pDataA->rows()); GMatrix* pDataC = GManifold::blendEmbeddings(pDataA, pRatios, pDataB, pNF->neighborCount(), pNeighborTable, startPoint); Holder<GMatrix> hDataC(pDataC); pDataC->print(cout); }