21 septembre 2023
21 septembre 2023
Terminal
MQL5
//+------------------------------------------------------------------+ //| Fonction de démarrage du programme de script | //+------------------------------------------------------------------+ 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) # Conversion en format ONNX 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())Ouvre le fichier onnx créé dans MetaEditor :
struct MyMap { long key[]; float value[]; };Nous avons utilisé ici des tableaux dynamiques avec les types correspondants. Dans ce cas, nous pouvons utiliser des tableaux fixes car la carte de ce modèle contient toujours 3 paires clé+valeur.
//--- déclaration du tableau pour récupérer les données de la couche de sortie output_probability MyMap output_probability[] ; ... //--- modèle en cours d'exécution OnnxRun(model,ONNX_DEBUG_LOGS,float_input,output_label,output_probability);
MetaEditor
Terminal Web