void TxToUniv(const CTransaction &tx, const uint256 &hashBlock,
              UniValue &entry) {
    entry.pushKV("txid", tx.GetId().GetHex());
    entry.pushKV("hash", tx.GetHash().GetHex());
    entry.pushKV("version", tx.nVersion);
    entry.pushKV("locktime", (int64_t)tx.nLockTime);

    UniValue vin(UniValue::VARR);
    for (unsigned int i = 0; i < tx.vin.size(); i++) {
        const CTxIn &txin = tx.vin[i];
        UniValue in(UniValue::VOBJ);
        if (tx.IsCoinBase()) {
            in.pushKV("coinbase",
                      HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
        } else {
            in.pushKV("txid", txin.prevout.hash.GetHex());
            in.pushKV("vout", (int64_t)txin.prevout.n);
            UniValue o(UniValue::VOBJ);
            o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true));
            o.pushKV("hex",
                     HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
            in.pushKV("scriptSig", o);
        }

        in.pushKV("sequence", (int64_t)txin.nSequence);
        vin.push_back(in);
    }

    entry.pushKV("vin", vin);

    UniValue vout(UniValue::VARR);
    for (unsigned int i = 0; i < tx.vout.size(); i++) {
        const CTxOut &txout = tx.vout[i];

        UniValue out(UniValue::VOBJ);

        UniValue outValue(UniValue::VNUM,
                          FormatMoney(txout.nValue.GetSatoshis()));
        out.pushKV("value", outValue);
        out.pushKV("n", (int64_t)i);

        UniValue o(UniValue::VOBJ);
        ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
        out.pushKV("scriptPubKey", o);
        vout.push_back(out);
    }

    entry.pushKV("vout", vout);

    if (!hashBlock.IsNull()) {
        entry.pushKV("blockhash", hashBlock.GetHex());
    }

    // the hex-encoded transaction. used the name "hex" to be consistent with
    // the verbose output of "getrawtransaction".
    entry.pushKV("hex", EncodeHexTx(tx));
}
Exemplo n.º 2
0
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
{
    entry.pushKV("txid", tx.GetHash().GetHex());
    entry.pushKV("hash", tx.GetWitnessHash().GetHex());
    entry.pushKV("version", tx.nVersion);
    entry.pushKV("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION));
    entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR);
    entry.pushKV("locktime", (int64_t)tx.nLockTime);

    UniValue vin(UniValue::VARR);
    for (unsigned int i = 0; i < tx.vin.size(); i++) {
        const CTxIn& txin = tx.vin[i];
        UniValue in(UniValue::VOBJ);
        if (tx.IsCoinBase())
            in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
        else {
            in.pushKV("txid", txin.prevout.hash.GetHex());
            in.pushKV("vout", (int64_t)txin.prevout.n);
            UniValue o(UniValue::VOBJ);
            o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true));
            o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
            in.pushKV("scriptSig", o);
            if (!tx.vin[i].scriptWitness.IsNull()) {
                UniValue txinwitness(UniValue::VARR);
                for (const auto& item : tx.vin[i].scriptWitness.stack) {
                    txinwitness.push_back(HexStr(item.begin(), item.end()));
                }
                in.pushKV("txinwitness", txinwitness);
            }
        }
        in.pushKV("sequence", (int64_t)txin.nSequence);
        vin.push_back(in);
    }
    entry.pushKV("vin", vin);

    UniValue vout(UniValue::VARR);
    for (unsigned int i = 0; i < tx.vout.size(); i++) {
        const CTxOut& txout = tx.vout[i];

        UniValue out(UniValue::VOBJ);

        UniValue outValue(UniValue::VNUM, FormatMoney(txout.nValue));
        out.pushKV("value", outValue);
        out.pushKV("n", (int64_t)i);

        UniValue o(UniValue::VOBJ);
        ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
        out.pushKV("scriptPubKey", o);
        vout.push_back(out);
    }
    entry.pushKV("vout", vout);

    if (!hashBlock.IsNull())
        entry.pushKV("blockhash", hashBlock.GetHex());

    entry.pushKV("hex", EncodeHexTx(tx)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction".
}
Exemplo n.º 3
0
	void LLSDMessageReaderTestObject::test<21>()
		// Binary 
	{
		std::vector<U8> outValue(2), inValue(2);
		inValue[0] = 0;
		inValue[1] = 1;
	  
		LLSDMessageReader msg = testType(inValue);
		msg.getBinaryData("block", "var", &(outValue[0]), inValue.size());
		ensure_equals("Ensure Binary", outValue, inValue);
	}
Exemplo n.º 4
0
ParamDialog::ParamDialog(QWidget *parent) :
    BaseDialog(parent),
    ui(new Ui::ParamDialog),
    nDialog(new NumberDialog(this)), param(NULL),
    name(), treeItem(0), editItem(0), isChanged(false)
{
    ui->setupUi(this);
    nDialog->move(parent->x()+570, parent->y()+130);
    connect(nDialog, SIGNAL(outValue()), this, SLOT(nDialogOutValueSLOT()));

    QIcon icon1(":/param/treeView1.png");
    QIcon icon2(":/param/treeView2.png");
    treeModel = new QStandardItemModel(ui->paramView);
    QStandardItem *item1 = new QStandardItem(icon1, QObject::tr("样本过滤设置"));
    treeModel->appendRow(item1);
    QStandardItem *item2 = new QStandardItem(icon1, QObject::tr("试剂设置"));
    treeModel->appendRow(item2);
    QFont font = item1->font();
    font.setPointSize(12);
    item1->setFont(font);
    item2->setFont(font);
    for(int i = 0; i < SystemBase::reagentNum; ++i) {
        QStandardItem *item = new QStandardItem(icon2, QObject::tr("试剂")+QString::number(i+1));
        item2->appendRow(item);
    }
    ui->paramView->setModel(treeModel);
    ui->paramView->expandAll();

    QDir dir(SystemBase::path);
    if(!dir.exists())
        dir.mkdir(SystemBase::path);
    QFile file(SystemBase::path + QString("/") + SystemBase::postfix);
    if(file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QTextStream in(&file);
        QString str = in.readLine();
        QFile f(SystemBase::path + str + QString(".") + SystemBase::postfix);
        if(f.exists()) {
            name = str;
            param = new ParamData(SystemBase::reagentNum, f);
            goto label;
        }
        file.close();
    }
    ui->paramView->setEnabled(false);
    ui->saveButton->setEnabled(false);
    ui->saveAsButton->setEnabled(false);
label:
    treeModel->setHorizontalHeaderLabels(QStringList(name));
    displayUpdate();
}
Exemplo n.º 5
0
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
{
    entry.pushKV("txid", tx.GetHash().GetHex());
    entry.pushKV("version", tx.nVersion);
    entry.pushKV("locktime", (int64_t)tx.nLockTime);

    UniValue vin(UniValue::VARR);
    BOOST_FOREACH(const CTxIn& txin, tx.vin) {
        UniValue in(UniValue::VOBJ);
        if (tx.IsCoinBase())
            in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
        else {
            in.pushKV("txid", txin.prevout.hash.GetHex());
            in.pushKV("vout", (int64_t)txin.prevout.n);
            UniValue o(UniValue::VOBJ);
            o.pushKV("asm", txin.scriptSig.ToString());
            o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
            in.pushKV("scriptSig", o);
        }
        in.pushKV("sequence", (int64_t)txin.nSequence);
        vin.push_back(in);
    }
    entry.pushKV("vin", vin);

    UniValue vout(UniValue::VARR);
    for (unsigned int i = 0; i < tx.vout.size(); i++) {
        const CTxOut& txout = tx.vout[i];

        UniValue out(UniValue::VOBJ);

        UniValue outValue(UniValue::VNUM, FormatMoney(txout.nValue));
        out.pushKV("value", outValue);
        out.pushKV("n", (int64_t)i);

        UniValue o(UniValue::VOBJ);
        ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
        out.pushKV("scriptPubKey", o);
        vout.push_back(out);
    }
    entry.pushKV("vout", vout);

    if (hashBlock != 0)
        entry.pushKV("blockhash", hashBlock.GetHex());
}
Exemplo n.º 6
0
void MayaGeoAttribute::transferValueFromMaya(MPlug &plug, MDataBlock &data){
	MDataHandle dataHandle = data.inputValue(plug);
	MFnMesh meshFn(dataHandle.asMesh());
	
	MFloatPointArray mayaPoints;
	meshFn.getPoints(mayaPoints);
	
	// collect points
	std::vector<Imath::V3f> coralPoints;
	for(int i = 0; i < mayaPoints.length(); ++i){
		MFloatPoint* mayaPoint = &mayaPoints[i];
		coralPoints.push_back(Imath::V3f(mayaPoint->x, mayaPoint->y, mayaPoint->z));
	}
	
	// collect faces
	int numPolys =  meshFn.numPolygons();
	std::vector<std::vector<int> > coralFaces(numPolys);
	for(int polyId = 0; polyId < numPolys; ++polyId){
		MIntArray mayaVertexList;
		meshFn.getPolygonVertices(polyId, mayaVertexList);
		
		int polyPoints = mayaVertexList.length();
		std::vector<int> coralFace(polyPoints);
		for(int i = 0; i < polyPoints; ++i){
			int pointId = mayaVertexList[i];
			coralFace[i] = pointId;
		}
		
		coralFaces[polyId] = coralFace;
	}
	
	// create coral geo
	coral::Geo *coralGeo = outValue();
	
	if(coralGeo->hasSameTopology(coralFaces)){
		coralGeo->setPoints(coralPoints);
	}
	else{
		coralGeo->build(coralPoints, coralFaces);
	}
	
	valueChanged();
}
Exemplo n.º 7
0
void rlSvgCat::catline(char *line_in)
{
  int i = 0;
  FILE *out = (FILE *) fout;
  line = line_in;

  while(line[i] != '\0' && line[i] != '\n')
  {
    while(line[i] == ' ' || line[i] == '\t' ) i++; // eliminate leading spaces
    // compare tags
    if     (strncmp(&line[i],"<?",2) == 0)
    {
      fputc(line[i++],out);
      fputc(line[i++],out);
      i = outUntil(i,"?>");
      fputc('\n',out);
    }
    else if(strncmp(&line[i],"<!",2) == 0) // comment
    {
      fprintf(out,"%s",&line[i]);
      if(strstr(&line[i],">") != NULL) return;
      while(fgets(line,sizeof(line)-1,(FILE *) fin) != 0)
      {
        fprintf(out,"%s",line);
        if(strstr(line,">") != NULL) return;
      }
      return;
    }
    /* removed after report by H. Schauerte
       normalize desc as well
    else if(strncmp(&line[i],"<desc",5) == 0)
    {
      fprintf(out,"%s",&line[i]);
      return;
    }
    */
    else if(strncmp(&line[i],"</",2) == 0)
    {
      if(strncmp(&line[i],"</svg>",6) == 0)
      {
        fprintf(out,"</svg>");
        return;
      }
      if(strncmp(&line[i],"</SVG>",6) == 0)
      {
        fprintf(out,"</SVG>");
        return;
      }
      if(strncmp(&line[i],"</tspan>",8) == 0)
      {
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc('\n',out);
        i--;
      }
      else if(strncmp(&line[i],"</TSPAN>",8) == 0)
      {
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc(line[i++],out);
        fputc('\n',out);
        i--;
      }
      else
      {
        fputc(line[i++],out);
        fputc(line[i++],out);
        i = outUntil(i,">");
        fputc('\n',out);
      }  
    }
    else if(strncmp(&line[i],"<",1) == 0)
    {
      fputc(line[i++],out);
      i = outUntilEnd(i);
    }
    else if(strncmp(&line[i],"/>",2) == 0)
    {
      fputc(line[i++],out);
      fputc(line[i++],out);
      fputc('\n',out);
    }
    else if(strncmp(&line[i],">",1) == 0)
    {
      fputc(line[i++],out);
      fputc('\n',out);
    }
    else
    {
      i = outValue(i);
      fputc('\n',out);
    }
    i++;
  }
}
void Backpropagation::train()
{
    vector<double> hideValue(hidenode, 0.0);
    vector<double> outValue(outnode, 0.0);

    vector<double> inodeOut(hidenode, 0.0);
    vector<double> hidenodeOut(outnode, 0.0);

    vector<double> hiderror(hidenode, 0.0);
    vector<double> allerror;

    vector<vector<double>> allhiderror;

    double e = 0.0;

    vector<vector<double>> hidevalueM;


    vector<vector<double>> wdetaInnode = wInode;
    vector<vector<double>> wdetaHidenode = wHnode;

    for (int i = 0; i < wInode.size(); i++)
    {
        for (int j = 0; j < wInode[0].size(); j++)
            wdetaInnode[i][j] = 0;
    }


    for (int i = 0; i < wHnode.size(); i++)
    {
        for (int j = 0; j < wHnode[0].size(); j++)
            wdetaHidenode[i][j] = 0;
    }


    for (int index = 0; index < train_set.size(); index++)
    {
        for (int i = 0; i < hidenode; i++)
        {
            for (int j = 0; j < innode; j++)
            {
                inodeOut[i] += train_set[index][j] * wInode[j][i];
            }
            hideValue[i] = sigmoid(inodeOut[i]);
        }

        for (int i = 0; i < outnode; i++)
        {
            for (int j = 0; j < hidenode; j++)
            {
                hidenodeOut[i] += hideValue[j] * wHnode[j][i];
            }
            outValue[i] = sigmoid(hidenodeOut[i]);
        }
        hidevalueM.push_back(hideValue);

        double err = (train_set[index][2] - outValue[0]) * (1 - outValue[0]) * outValue[0];

        allerror.push_back(err);

        double er = train_set[index][2] - outValue[0];
        e += fabs(er) * fabs(er);


        for (int i = 0; i < hidenode; i++)
        {
            wdetaHidenode[i][0] += rate * err * hideValue[i];
        }

        for (int i = 0; i < hidenode; i++)
        {
            hiderror[i] = err * wHnode[i][0] * (1 - hideValue[i]) * hideValue[i];
        }
        for (int i = 0; i < innode; i++)
        {
            for (int j = 0; j < hidenode; j++)
            {
                wdetaInnode[i][j] += hiderror[j] * train_set[index][i];
            }
        }
    }

    for (int i = 0; i < wInode.size(); i++)
    {
        for (int j = 0; j < wInode[0].size(); j++)
            wInode[i][j]+=wdetaInnode[i][j];
    }


    for (int i = 0; i < wHnode.size(); i++)
    {
        for (int j = 0; j < wHnode[0].size(); j++)
            wHnode[i][j]+=wdetaHidenode[i][j];
    }

    this->error = e / 8;
}
Exemplo n.º 9
0
void rlSvgCat::catline()
{
  int i = 0;
  FILE *out = (FILE *) fout;

  while(line[i] != '\0' && line[i] != '\n')
  {
    while(line[i] == ' ' || line[i] == '\t' ) i++; // eliminate leading spaces
    // compare tags
    if     (strncmp(&line[i],"<?",2) == 0)
    {
      fputc(line[i++],out);
      fputc(line[i++],out);
      i = outUntil(i,"?>");
      fputc('\n',out);
    }
    else if(strncmp(&line[i],"<!",2) == 0) // comment
    {
      fprintf(out,"%s",&line[i]);
      if(strstr(&line[i],">") != NULL) return;
      while(fgets(line,sizeof(line)-1,(FILE *) fin) != 0)
      {
        fprintf(out,"%s",line);
        if(strstr(line,">") != NULL) return;
      }
      return;
    }
    else if(strncmp(&line[i],"<desc",5) == 0)
    {
      fprintf(out,"%s",&line[i]);
      return;
    }
    else if(strncmp(&line[i],"</",2) == 0)
    {
      if(strncmp(&line[i],"</svg>",6) == 0)
      {
        fprintf(out,"</svg>");
        return;
      }
      if(strncmp(&line[i],"</SVG>",6) == 0)
      {
        fprintf(out,"</SVG>");
        return;
      }
      fputc(line[i++],out);
      fputc(line[i++],out);
      i = outUntil(i,">");
      fputc('\n',out);
    }
    else if(strncmp(&line[i],"<",1) == 0)
    {
      fputc(line[i++],out);
      i = outUntilEnd(i);
    }
    else if(strncmp(&line[i],"/>",2) == 0)
    {
      fputc(line[i++],out);
      fputc(line[i++],out);
      fputc('\n',out);
    }
    else if(strncmp(&line[i],">",1) == 0)
    {
      fputc(line[i++],out);
      fputc('\n',out);
    }
    else
    {
      i = outValue(i);
      fputc('\n',out);
    }
    i++;
  }
}