量化合約交易機(jī)器人系統(tǒng)開發(fā)(項(xiàng)目開發(fā))丨合約量化交易機(jī)器人系統(tǒng)開發(fā)(成熟案例)
數(shù)據(jù)層我們可以理解成數(shù)據(jù)庫(kù),只不過對(duì)于區(qū)塊鏈來講,這個(gè)數(shù)據(jù)庫(kù)是不可篡改的、分布式的數(shù)據(jù)庫(kù),也就是我們所謂的“分布式賬本”在數(shù)據(jù)層上,也就是在這個(gè)“分布式賬本”上,存放著區(qū)塊鏈上的數(shù)據(jù)信息,封裝著區(qū)塊的塊鏈?zhǔn)浇Y(jié)構(gòu)、非對(duì)稱加密技術(shù)、哈希算法等技術(shù)手段,來保證數(shù)據(jù)在全網(wǎng)公開的情況下的安全性問題。
區(qū)塊鏈最常見的數(shù)據(jù)結(jié)構(gòu)當(dāng)然就是單鏈?zhǔn)浇Y(jié)構(gòu),像一條鐵鏈一樣,一個(gè)節(jié)點(diǎn)只有一個(gè)前序節(jié)點(diǎn)和一個(gè)后續(xù)節(jié)點(diǎn)。
int main(int argc,const char*argv[]){
if(argc<4){
DLOG(INFO)<<"Usage:./quantized.out src.mnn dst.mnn preTreatConfig.jsonn";
return 0;
}
const char*modelFile=argv[1];
const char*preTreatConfig=argv[3];
const char*dstFile=argv[2];
DLOG(INFO)<<">>>modelFile:"<<modelFile;
DLOG(INFO)<<">>>preTreatConfig:"<<preTreatConfig;
DLOG(INFO)<<">>>dstFile:"<<dstFile;
//加載待量化的模型
std::unique_ptr<MNN::NetT>netT;
{
std::ifstream input(modelFile);
std::ostringstream outputOs;
outputOs<<input.rdbuf();
netT=MNN::UnPackNet(outputOs.str().c_str());
}
//temp build net for inference
flatbuffers::FlatBufferBuilder builder(1024);
auto offset=MNN::Net::Pack(builder,netT.get());
builder.Finish(offset);
int size=builder.GetSize();
auto ocontent=builder.GetBufferPointer();
//model buffer for creating mnn Interpreter
std::unique_ptr<uint8_t>modelForInference(new uint8_t[size]);
memcpy(modelForInference.get(),ocontent,size);
std::unique_ptr<uint8_t>modelOriginal(new uint8_t[size]);
memcpy(modelOriginal.get(),ocontent,size);
netT.reset();
netT=MNN::UnPackNet(modelOriginal.get());
//quantize model's weight
DLOG(INFO)<<"Calibrate the feature and quantize model...";
//構(gòu)建Calibration對(duì)象,負(fù)責(zé)量化
std::shared_ptr<Calibration>calibration(
new Calibration(netT.get(),modelForInference.get(),size,preTreatConfig));
//執(zhí)行量化,更新參數(shù)為int8
calibration->runQuantizeModel();
//將量化的參數(shù)寫入json文件
calibration->dumpTensorScales(dstFile);
DLOG(INFO)<<"Quantize model done!";
//保存量化后的模型
flatbuffers::FlatBufferBuilder builderOutput(1024);
builderOutput.ForceDefaults(true);
auto len=MNN::Net::Pack(builderOutput,netT.get());
builderOutput.Finish(len);
{
std::ofstream output(dstFile);
output.write((const char*)builderOutput.GetBufferPointer(),builderOutput.GetSize());
}
return 0;
}