21 septiembre 2023
21 septiembre 2023
Terminal
MQL5
//+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ 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)]] */ }
from sys import argv data_path=argv[0] last_index=data_path.rfind("\\")+1 data_path=data_path[0:last_index] from sklearn.datasets import load_iris iris_dataset = load_iris() from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(iris_dataset['data'], iris_dataset['target'], random_state=0) from sklearn.neighbors import KNeighborsClassifier knn = KNeighborsClassifier(n_neighbors=1) knn.fit(X_train, y_train) # Convert into ONNX format from skl2onnx import convert_sklearn from skl2onnx.common.data_types import 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())Abra el archivo onnx creado en MetaEditor:
struct MyMap { long key[]; float value[]; };Aquí hemos utilizado arrays dinámicos con los tipos correspondientes. En este caso, podemos usar arrays fijos, ya que para este modelo Map siempre contiene 3 pares clave+valor.
//--- declaramos un array para recibir los datos de la capa de salida output_probability MyMap output_probability[]; ... //--- ejecución del modelo OnnxRun(modelo,ONNX_DEBUG_LOGS,float_input,output_label,output_probability);
MetaEditor
MetaTrader 5 Web Terminal build 3980