21 九月 2023
21 九月 2023
程序端
MQL5
//+------------------------------------------------------------------+ //| 脚本程序起始函数 | //+------------------------------------------------------------------+ void OnStart() { complex a=1+1i; complex b=a.Conjugate(); Print(a, " ", b); /* (1,1) (1,-1) */ vectorc va= {0.1+0.1i, 0.2+0.2i, 0.3+0.3i}; vectorc vb=va.Conjugate(); Print(va, " ", vb); /* [(0.1,0.1),(0.2,0.2),(0.3,0.3)] [(0.1,-0.1),(0.2,-0.2),(0.3,-0.3)] */ matrixc ma(2, 3); ma.Row(va, 0); ma.Row(vb, 1); matrixc mb=ma.Conjugate(); Print(ma); Print(mb); /* [[(0.1,0.1),(0.2,0.2),(0.3,0.3)] [(0.1,-0.1),(0.2,-0.2),(0.3,-0.3)]] [[(0.1,-0.1),(0.2,-0.2),(0.3,-0.3)] [(0.1,0.1),(0.2,0.2),(0.3,0.3)]] */ ma=mb.Transpose().Conjugate(); Print(ma); /* [[(0.1,0.1),(0.1,-0.1)] [(0.2,0.2),(0.2,-0.2)] [(0.3,0.3),(0.3,-0.3)]] */ }
从 sys 导入 argv data_path=argv[0] last_index=data_path.rfind("\\")+1 data_path=data_path[0:last_index] 从 sklearn.datasets 导入 load_iris iris_dataset = load_iris() 从 sklearn.model_selection 导入 train_test_split X_train, X_test, y_train, y_test = train_test_split(iris_dataset['data'], iris_dataset['target'], random_state=0) 从 sklearn.neighbors 导入 KNeighborsClassifier knn = KNeighborsClassifier(n_neighbors=1) knn.fit(X_train, y_train) # 转换 为 ONNX格式 从 skl2onnx 导入 convert_sklearn 从 skl2onnx.common.data_types 导入 FloatTensorType initial_type = [('float_input', FloatTensorType([None, 4]))] onx = convert_sklearn(knn, initial_types=initial_type) path = data_path+"iris.onnx" with open(path, "wb") as f: f.write(onx.SerializeToString())在MetaEditor中打开创建的onnx文件:
struct MyMap { long key[]; float value[]; };这里我们使用具有适当类型的动态数组。在这种情况下,我们可以使用固定数组,因为这个模型的Map始终包含3个键+值对。
//--- 声明一个数组来接收来自输出层output_probability的数据 MyMap output_probability[]; ... //--- 模型运行 OnnxRun(model,ONNX_DEBUG_LOGS,float_input,output_label,output_probability);
MetaEditor