Ejemplo n.º 1
0
GVN::Value * GVN::getValue(const OpValue::Kind kind, const GVN::Value & LV, const GVN::Value & RV)
{
    OpValue ov(kind, LV.value, RV.value);

    switch (kind)
    {
        case OpValue::PLUS:
            return getValue([](const MultivariatePolynomial & LMP, const MultivariatePolynomial & RMP)
            {
                return LMP + RMP;
            }, LV, RV, ov);
        case OpValue::MINUS:
            return getValue([](const MultivariatePolynomial & LMP, const MultivariatePolynomial & RMP)
            {
                return LMP - RMP;
            }, LV, RV, ov);
        case OpValue::TIMES:
        case OpValue::DOTTIMES:
            return getValue([](const MultivariatePolynomial & LMP, const MultivariatePolynomial & RMP)
            {
                return LMP * RMP;
            }, LV, RV, ov);
        case OpValue::RDIV:
        case OpValue::DOTRDIV:
            return getValue([](const MultivariatePolynomial & LMP, const MultivariatePolynomial & RMP)
            {
                return LMP / RMP;
            }, LV, RV, ov);
        case OpValue::POWER:
        case OpValue::DOTPOWER:
            return getValue([](const MultivariatePolynomial & LMP, const MultivariatePolynomial & RMP)
            {
                return LMP ^ RMP;
            }, LV, RV, ov);
        default:
            return getValue([](const MultivariatePolynomial & LMP, const MultivariatePolynomial & RMP)
            {
                return MultivariatePolynomial::getInvalid();
            }, LV, RV, ov);
    }
}
Ejemplo n.º 2
0
OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL) {

    try {
        if(orderMap == NULL) {
            OrderVector ov;

            for(int i=0; i<data.size(); i++) {
                int binSize = m->getNumNames(data[i]);
                for(int j=0; j<binSize; j++) {
                    ov.push_back(i);
                }
            }
            random_shuffle(ov.begin(), ov.end());
            ov.setLabel(label);
            ov.getNumBins();

            return ov;

        }
        else {
            OrderVector ov(numSeqs);

            for(int i=0; i<data.size(); i++) {
                string listOTU = data[i];
                int length = listOTU.size();

                string seqName="";

                for(int j=0; j<length; j++) {

                    if(listOTU[j] != ',') {
                        seqName += listOTU[j];
                    }
                    else {
                        if(orderMap->count(seqName) == 0) {
                            m->mothurOut(seqName + " not found, check *.names file\n");
                            exit(1);
                        }

                        ov.set((*orderMap)[seqName], i);
                        seqName = "";
                    }
                }

                if(orderMap->count(seqName) == 0) {
                    m->mothurOut(seqName + " not found, check *.names file\n");
                    exit(1);
                }
                ov.set((*orderMap)[seqName], i);
            }

            ov.setLabel(label);
            ov.getNumBins();

            return ov;
        }
    }
    catch(exception& e) {
        m->errorOut(e, "ListVector", "getOrderVector");
        exit(1);
    }
}
Ejemplo n.º 3
0
std::ostream& operator << (std::ostream& ostr, const value_t& v)
{
    stream_output_visitor ov(ostr);
    boost::apply_visitor(ov, v);    
    return ostr;
}
Ejemplo n.º 4
0
 void Uniform::setColorElement(const omega::Color& value, uint index)
 {
     osg::Vec4 ov(value[0], value[1], value[2], value[3]);
     myOsgUniform->setElement(index, ov);
 }
Ejemplo n.º 5
0
 void Uniform::setVector3fElement(const omega::Vector3f& value, uint index)
 {
     osg::Vec3 ov(value[0], value[1], value[2]);
     myOsgUniform->setElement(index, ov);
 }
Ejemplo n.º 6
0
 void Uniform::setColor(const omega::Color& value)
 {
     osg::Vec4 ov(value[0], value[1], value[2], value[3]);
     myOsgUniform->set(ov);
 }
Ejemplo n.º 7
0
 void Uniform::setVector3f(const omega::Vector3f& value)
 {
     osg::Vec3 ov(value[0], value[1], value[2]);
     myOsgUniform->set(ov);
 }
Ejemplo n.º 8
0
 void Uniform::setVector2f(const omega::Vector2f& value)
 {
     osg::Vec2 ov(value[0], value[1]);
     myOsgUniform->set(ov);
 }
Ejemplo n.º 9
0
bool wxvbamApp::OnInit()
{
	// use consistent names for config
	SetAppName(_("vbam"));
#if (wxMAJOR_VERSION >= 3)
	SetAppDisplayName(_T("VisualBoyAdvance-M"));
#endif
	// load system default locale, if available
	locale.Init();
	locale.AddCatalog(_T("wxvbam"));
	// make built-in xrc file available
	// this has to be done before parent OnInit() so xrc dump works
	wxFileSystem::AddHandler(new wxMemoryFSHandler);
	wxFileSystem::AddHandler(new wxArchiveFSHandler);
	wxMemoryFSHandler::AddFileWithMimeType(wxT("wxvbam.xrs"), builtin_xrs, sizeof(builtin_xrs), wxT("application/zip"));

	if (!wxApp::OnInit())
		return false;

	// prepare for loading xrc files
	wxXmlResource* xr = wxXmlResource::Get();
	// note: if linking statically, next 2 pull in lot of unused code
	// maybe in future if not wxSHARED, load only builtin-needed handlers
	xr->InitAllHandlers();
	wxInitAllImageHandlers();
	get_config_path(config_path);
	// first, load override xrcs
	// this can only override entire root nodes
	// 2.9 has LoadAllFiles(), but this is 2.8, so we'll do it manually
	wxString cwd = wxGetCwd();

	for (int i = 0; i < config_path.size(); i++)
		if (wxDirExists(config_path[i]) && wxSetWorkingDirectory(config_path[i]))
		{
			// *.xr[cs] doesn't work (double the number of scans)
			// 2.9 gives errors for no files found, so manual precheck needed
			// (yet another double the number of scans)
			if (!wxFindFirstFile(wxT("*.xrc")).empty())
				xr->Load(wxT("*.xrc"));

			if (!wxFindFirstFile(wxT("*.xrs")).empty())
				xr->Load(wxT("*.xrs"));
		}

	wxFileName xrcDir(GetConfigurationPath() + wxT("//xrc"), wxEmptyString);

	if (xrcDir.DirExists() && wxSetWorkingDirectory(xrcDir.GetFullPath()) && !wxFindFirstFile(wxT("*.xrc")).empty())
	{
		xr->Load(wxT("*.xrc"));
	}
	else
	{
		// finally, load built-in xrc
		xr->Load(wxT("memory:wxvbam.xrs"));
	}

	wxSetWorkingDirectory(cwd);
	// set up config file
	// this needs to be in a subdir to support other config as well
	// but subdir flag behaves differently 2.8 vs. 2.9.  Oh well.
	// NOTE: this does not support XDG (freedesktop.org) paths
#if defined(__WXMSW__) || defined(__APPLE__)
	wxFileName vbamconf(GetConfigurationPath(), _T("vbam.ini"));
	cfg = new wxFileConfig(wxT("vbam"), wxEmptyString,
	                       vbamconf.GetFullPath(),
	                       wxEmptyString, wxCONFIG_USE_LOCAL_FILE);
#else
	cfg = new wxFileConfig(wxEmptyString, wxEmptyString, wxEmptyString,
	                       wxEmptyString,
	                       // style =
	                       wxCONFIG_USE_GLOBAL_FILE | wxCONFIG_USE_LOCAL_FILE |
	                       wxCONFIG_USE_SUBDIR);
#endif
	// set global config for e.g. Windows font mapping
	wxFileConfig::Set(cfg);
	// yet another bug/deficiency in wxConfig: dirs are not created if needed
	// since a default config is always written, dirs are always needed
	// Can't figure out statically if using wxFileConfig w/o duplicating wx's
	// logic, so do it at run-time
	// wxFileConfig *f = wxDynamicCast(cfg, wxFileConfig);
	// wxConfigBase does not derive from wxObject!!! so no wxDynamicCast
	wxFileConfig* fc = dynamic_cast<wxFileConfig*>(cfg);

	if (fc)
	{
		wxFileName s(wxFileConfig::GetLocalFileName(GetAppName()));
		// at least up to 2.8.12, GetLocalFileName returns the dir if
		// SUBDIR is specified instead of actual file name
		// and SUBDIR only affects UNIX
#if defined(__UNIX__) && !wxCHECK_VERSION(2,9,0)
		s.AppendDir(s.GetFullName());
#endif
		// only the path part gets created
		// note that 0777 is default (assumes umask will do og-w)
		s.Mkdir(0777, wxPATH_MKDIR_FULL);
		s = wxFileName::DirName(GetConfigurationPath());
		s.Mkdir(0777, wxPATH_MKDIR_FULL);
	}

	load_opts();

	// process command-line options
	for (int i = 0; i < pending_optset.size(); i++)
	{
		wxString p = pending_optset[i];
		size_t eqat = p.find(wxT('='));
		p[eqat] = 0;
		opt_set(p.c_str(), p.c_str() + eqat + 1);
	}

	pending_optset.clear();
	wxFileName vba_over(GetConfigurationPath(), wxT("vba-over.ini"));
	wxFileName rdb(GetConfigurationPath(), wxT("Nintendo - Game Boy Advance*.dat"));
	wxFileName scene_rdb(GetConfigurationPath(), wxT("Nintendo - Game Boy Advance (Scene)*.dat"));
	wxFileName nointro_rdb(GetConfigurationPath(), wxT("Official No-Intro Nintendo Gameboy Advance Number (Date).xml"));
	wxString f = wxFindFirstFile(nointro_rdb.GetFullPath(), wxFILE);

	if (!f.empty() && wxFileName(f).IsFileReadable())
		rom_database_nointro = f;

	f = wxFindFirstFile(scene_rdb.GetFullPath(), wxFILE);

	if (!f.empty() && wxFileName(f).IsFileReadable())
		rom_database_scene = f;

	f = wxFindFirstFile(rdb.GetFullPath(), wxFILE);

	while (!f.empty())
	{
		if (f == rom_database_scene.GetFullPath())
		{
			f = wxFindNextFile();
		}
		else if (wxFileName(f).IsFileReadable())
		{
			rom_database = f;
			break;
		}
	}

	// load vba-over.ini
	// rather than dealing with wxConfig's broken search path, just use
	// the same one that the xrc overrides use
	// this also allows us to override a group at a time, add commments, and
	// add the file from which the group came
	wxMemoryInputStream mis(builtin_over, sizeof(builtin_over));
	overrides = new wxFileConfig(mis);
	wxRegEx cmtre;
	// not the most efficient thing to do: read entire file into a string
	// just to parse the comments out
	wxString bovs((const char*)builtin_over, wxConvUTF8, sizeof(builtin_over));
	bool cont;
	wxString s;
	long grp_idx;
#define CMT_RE_START wxT("(^|[\n\r])# ?([^\n\r]*)(\r?\n|\r)\\[")

	for (cont = overrides->GetFirstGroup(s, grp_idx); cont;
	        cont = overrides->GetNextGroup(s, grp_idx))
	{
		// apparently even MacOSX sometimes uses the old \r by itself
		wxString cmt(CMT_RE_START);
		cmt += s + wxT("\\]");

		if (cmtre.Compile(cmt) && cmtre.Matches(bovs))
			cmt = cmtre.GetMatch(bovs, 2);
		else
			cmt = wxEmptyString;

		overrides->Write(s + wxT("/comment"), cmt);
	}

	if (vba_over.FileExists())
	{
		wxStringOutputStream sos;
		wxFileInputStream fis(vba_over.GetFullPath());
		// not the most efficient thing to do: read entire file into a string
		// just to parse the comments out
		fis.Read(sos);
		// rather than assuming the file is seekable, use the string we just
		// read as an input stream
		wxStringInputStream sis(sos.GetString());
		wxFileConfig ov(sis);

		for (cont = ov.GetFirstGroup(s, grp_idx); cont;
		        cont = ov.GetNextGroup(s, grp_idx))
		{
			overrides->DeleteGroup(s);
			overrides->SetPath(s);
			ov.SetPath(s);
			overrides->Write(wxT("path"), GetConfigurationPath());
			// apparently even MacOSX sometimes uses \r by itself
			wxString cmt(CMT_RE_START);
			cmt += s + wxT("\\]");

			if (cmtre.Compile(cmt) && cmtre.Matches(sos.GetString()))
				cmt = cmtre.GetMatch(sos.GetString(), 2);
			else
				cmt = wxEmptyString;

			overrides->Write(wxT("comment"), cmt);
			long ent_idx;

			for (cont = ov.GetFirstEntry(s, ent_idx); cont;
			        cont = ov.GetNextEntry(s, ent_idx))
				overrides->Write(s, ov.Read(s, wxEmptyString));

			ov.SetPath(wxT("/"));
			overrides->SetPath(wxT("/"));
		}
	}

	// create the main window
	frame = wxDynamicCast(xr->LoadFrame(NULL, wxT("MainFrame")), MainFrame);

	if (!frame)
	{
		wxLogError(_("Could not create main window"));
		return false;
	}

	// Create() cannot be overridden easily
	if (!frame->BindControls())
		return false;

	frame->Show(true);
	return true;
}
Ejemplo n.º 10
0
void
L1Graph::L1Minimization(SpMatrix<float>& alpha,std::vector<int>& neighborhood)
{
    //neighborhood contains cidx
    int p_num=index_->size();
    int f_dim=(*features_)[0].size();
    Matrix<float> X(f_dim, p_num - 1);

    //construct matrix X
    std::map<int,int> map_gl; //map between global and local point index
    for(int j = 0, k = 0; j < p_num; j++) { //cols
        int id=(*index_)[j];
        if(id==cidx_) {
            continue;
        }
        Util::StdVector2MatrixCol((*features_)[id], X, k);
        map_gl.insert(make_pair<int,int>(k,id));
        ++k;
    }

    //TODO:dont use I
    //construct I
    // Matrix<float> I(f_dim,f_dim);
    // I.eye();
    // Util::Matrix2File(I,"I.txt");
    // Matrix<float> B(f_dim, f_dim + p_num - 1);
    // X.merge(I, B);
    // Util::Matrix2File(B,"B.txt");
    //clean
    // X.clear();
    // I.clear();
    //using lasso
    Matrix<float> x; //x=Ba
    Util::StdVector2Matrix((*features_)[cidx_], x);
    float lambda = 0.01; //lambda
    int L = (*features_)[0].size(); //max non-zero number
    // int L = 20; //max non-zero number
    SpMatrix<float> all;

    //TODO:debug in matlab
    ofstream fout("f.txt");
    for (int i = 0; i < x.m(); i++) {
        for (int j = 0; j < x.n(); j++) {
            fout<<x(i,j)<<" "; 
        }
        fout<<std::endl;
    }
    fout.close();
    ofstream dout("d.txt");
    for (int i = 0; i < X.m(); i++) {
        for (int j = 0; j < X.n(); j++) {
            dout<<X(i,j)<<" "; 
        }
        dout<<std::endl;
    }
    dout.close();


    lasso2<float>(x, X, all, L, lambda , 0 , PENALTY , true); //TODO:X->B

    Util::SubSpMatrix(all,alpha,p_num-1);
    // all.print("all");
    // alpha.print("alpha");
    // getchar();


    Matrix<float> tmp;
    X.mult(alpha,tmp);
    x.add(tmp,-1);
    std::cout<<(0.5*x.normFsq())<<" "<<(lambda*alpha.asum())<<" "<<(0.5*x.normFsq())/(lambda*alpha.asum())<<std::endl;


    //save for vis
    std::vector<int> mk;
    std::vector<float> mv;

    for(int ii = 0; ii < alpha.n(); ++ii) {
        //TODO:calls for pB and pE are not consist
        for(int j = alpha.pB(ii); j < alpha.pE()[ii]; ++j) {
            //<i,j>->all.v(j)
            mk.push_back(map_gl[j]);
            mv.push_back(alpha.v(j));
            neighborhood.push_back(map_gl[j]);
        }
    }

    std::string namev = "debug/" + boost::lexical_cast<std::string>(cidx_) + ".xyznq";
    ofstream ov(namev.c_str());

    for(int ii = 0; ii < cloud_->size(); ++ii) {
        if(ii == cidx_) {
            ov << cloud_->points[ii].x << " " << cloud_->points[ii].y << " " << cloud_->points[ii].z << " 0 0 0 1" << std::endl;
        } else {
            std::vector<int>::iterator it = find(mk.begin(), mk.end(), ii);
            if(it != mk.end()) {
                int dis = std::distance(mk.begin(), it);
                ov << cloud_->points[ii].x << " " << cloud_->points[ii].y << " " << cloud_->points[ii].z << " 0 0 0 " << mv[dis] << std::endl;
                // ov << cloud_->points[ii].x <<" " << cloud_->points[ii].y << " " << cloud_->points[ii].z << " 0 0 0 0" << std::endl;
            } else {
                ov << cloud_->points[ii].x << " " << cloud_->points[ii].y << " " << cloud_->points[ii].z << " 0 0 0 -1" << std::endl;
            }
        }
    }

    ov.close();
    return ;
}       /* -----  end of method L1Graph::L1Minimization  ----- */
Ejemplo n.º 11
0
  ExecStatus
  Weights<View>::propagate(Space& home, const ModEventDelta&) {

    ModEvent me = ME_SET_NONE;

    if (!x.assigned()) {
      // Collect the weights of the elements in the unknown set in an array
      int size = elements.size();
      Region r(home);
      int* currentWeights = r.alloc<int>(size);

      UnknownRanges<View> ur(x);
      Iter::Ranges::ToValues<UnknownRanges<View> > urv(ur);
      for (int i=0; i<size; i++) {
        if (!urv() || elements[i]<urv.val()) {
          currentWeights[i] = 0;
        } else {
          assert(elements[i] == urv.val());
          currentWeights[i] = weights[i];
          ++urv;
        }
      }

      // Sort the weights of the unknown elements
      IntLess il;
      Support::quicksort<int>(currentWeights, size, il);

      // The maximum number of elements that can still be added to x
      int delta = static_cast<int>(std::min(x.unknownSize(), x.cardMax() - x.glbSize()));

      // The weight of the elements already in x
      GlbRanges<View> glb(x);
      int glbWeight = weightI<GlbRanges<View> >(elements, weights, glb);

      // Compute the weight of the current lower bound of x, plus at most
      // delta-1 further elements with smallest negative weights. This weight
      // determines which elements in the upper bound cannot possibly be
      // added to x (those whose weight would exceed the capacity even if
      // all other elements are minimal)
      int lowWeight = glbWeight;
      for (int i=0; i<delta-1; i++) {
        if (currentWeights[i] >= 0)
          break;
        lowWeight+=currentWeights[i];
      }

      // Compute the lowest possible weight of x. If there is another element
      // with negative weight left, then add its weight to lowWeight.
      // Otherwise lowWeight is already the lowest possible weight.
      int lowestWeight = lowWeight;
      if (delta>0 && currentWeights[delta-1]<0)
        lowestWeight+=currentWeights[delta-1];

      // If after including the minimal number of required elements,
      // no more element with negative weight is available, then
      // a tighter lower bound can be computed.
      if ( (x.cardMin() - x.glbSize() > 0 &&
            currentWeights[x.cardMin() - x.glbSize() - 1] >= 0) ||
           currentWeights[0] >= 0 ) {
        int lowestPosWeight = glbWeight;
        for (unsigned int i=0; i<x.cardMin() - x.glbSize(); i++) {
          lowestPosWeight += currentWeights[i];
        }
        lowestWeight = std::max(lowestWeight, lowestPosWeight);        
      }

      // Compute the highest possible weight of x as the weight of the lower
      // bound plus the weight of the delta heaviest elements still in the
      // upper bound.
      int highestWeight = glbWeight;
      for (int i=0; i<delta; i++) {
        if (currentWeights[size-i-1]<=0)
          break;
        highestWeight += currentWeights[size-i-1];
      }

      // Prune the weight using the computed bounds
      GECODE_ME_CHECK(y.gq(home, lowestWeight));
      GECODE_ME_CHECK(y.lq(home, highestWeight));

      // Exclude all elements that are too heavy from the set x.
      // Elements are too heavy if their weight alone already
      // exceeds the remaining capacity
      int remainingCapacity = y.max()-lowWeight;

      UnknownRanges<View> ur2(x);
      Iter::Ranges::ToValues<UnknownRanges<View> > urv2(ur2);
      OverweightValues<Iter::Ranges::ToValues<UnknownRanges<View> > >
        ov(remainingCapacity, elements, weights, urv2);
      Iter::Values::ToRanges<OverweightValues<
        Iter::Ranges::ToValues<UnknownRanges<View> > > > ovr(ov);
      me = x.excludeI(home, ovr);
      GECODE_ME_CHECK(me);
    }
    if (x.assigned()) {
      // If x is assigned, just compute its weight and assign y.
      GlbRanges<View> glb(x);
      int w =
        weightI<GlbRanges<View> >(elements, weights, glb);
      GECODE_ME_CHECK(y.eq(home, w));
      return home.ES_SUBSUMED(*this);
    }

    return me_modified(me) ? ES_NOFIX : ES_FIX;
  }