227 lines
5.3 KiB
Plaintext
227 lines
5.3 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"#use \"topfind\";;\n",
|
|
"#require \"jupyter.notebook\";;\n",
|
|
"#require \"lacaml.top\";;\n",
|
|
"#require \"alcotest\";;\n",
|
|
"#require \"str\";;\n",
|
|
"#require \"bigarray\";;\n",
|
|
"#require \"zarith\";;\n",
|
|
"#require \"getopt\";;\n",
|
|
"open Lacaml.D"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"let n_ao = 8;;\n",
|
|
"let n_mo = 6;; \n",
|
|
"let ran=\n",
|
|
"Mat.random ~range:1. ~from:0. n_ao n_mo;; "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"(* Extraction des colonnes i,j,k,... d'une matrice à partir d'une liste [i,j,k,...] *)\n",
|
|
"\n",
|
|
"let toto = [1;2;3];;\n",
|
|
"(*\n",
|
|
"ran;;\n",
|
|
"let new_ran = Mat.transpose_copy ran ;;\n",
|
|
"\n",
|
|
"let vec = Mat.to_col_vecs ran;;\n",
|
|
"\n",
|
|
"vec.(0);;\n",
|
|
"\n",
|
|
"let f a = vec.(a);;\n",
|
|
"\n",
|
|
"let n = List.map f toto;;\n",
|
|
"\n",
|
|
"let vec_list = [vec.(0);vec.(1)];;\n",
|
|
"\n",
|
|
"\n",
|
|
"let mat_n = Mat.of_col_vecs_list vec_list;;\n",
|
|
"\n",
|
|
"\n",
|
|
"let occ ran toto = \n",
|
|
" let new_ran = Mat.transpose_copy ran\n",
|
|
" in\n",
|
|
" let vec = Mat.to_col_vecs new_ran\n",
|
|
" in \n",
|
|
" let f a = vec.(a+1)\n",
|
|
" in \n",
|
|
" let vec_list = List.map f toto \n",
|
|
"in Mat.of_col_vecs_list vec_list;;\n",
|
|
"\n",
|
|
"occ ran toto;;\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"let list_a = [0;0;2;0;5];;\n",
|
|
"\n",
|
|
"let new_list list= List.filter (fun x -> x > 0.) list;;\n",
|
|
"\n",
|
|
"let vecto = Vec.init 8 (fun i -> if List.mem i toto\n",
|
|
"then 0.\n",
|
|
"else float_of_int(i) );;\n",
|
|
"\n",
|
|
"let vecto_list = Vec.to_list vecto;;\n",
|
|
"\n",
|
|
"\n",
|
|
"new_list vecto_list;;\n",
|
|
"*)\n",
|
|
"(******************)\n",
|
|
"(*\n",
|
|
"ran;;\n",
|
|
"let vec_of_mat = Mat.to_col_vecs ran;;\n",
|
|
"let f a = vec_of_mat.(a-1);;\n",
|
|
"vec_of_mat.(5);;\n",
|
|
"let vec_list = List.map f toto;;\n",
|
|
"let new_m = Mat.of_col_vecs_list vec_list;;\n",
|
|
"*)\n",
|
|
"\n",
|
|
"(* Fp *)\n",
|
|
"let miss_elem mat list = \n",
|
|
" let n_mo = Mat.dim2 mat\n",
|
|
" in\n",
|
|
" let vec = Vec.init (n_mo) (fun i ->\n",
|
|
" if List.mem i list\n",
|
|
" then 0.\n",
|
|
" else float_of_int(i))\n",
|
|
" in\n",
|
|
" let vec_list = Vec.to_list vec\n",
|
|
" in\n",
|
|
" let g a = int_of_float(a)\n",
|
|
" in\n",
|
|
" let vec_list_int = List.map g vec_list\n",
|
|
" \n",
|
|
" in\n",
|
|
" List.filter (fun x -> x > 0) vec_list_int;;\n",
|
|
"\n",
|
|
"let split_mat mat list =\n",
|
|
" let vec_of_mat = Mat.to_col_vecs mat\n",
|
|
" in\n",
|
|
" let f a = vec_of_mat.(a-1)\n",
|
|
" in\n",
|
|
" let vec_list_1 = List.map f list\n",
|
|
" in\n",
|
|
" let list_2 = miss_elem mat list\n",
|
|
" in\n",
|
|
" let vec_list_2 = List.map f list_2\n",
|
|
"in (Mat.of_col_vecs_list vec_list_1,Mat.of_col_vecs_list vec_list_2);; \n",
|
|
"\n",
|
|
"let m_occ , m_vir = split_mat ran toto;;\n",
|
|
"\n",
|
|
"(*\n",
|
|
"let miss_elem mat list = \n",
|
|
" let n_mo = Mat.dim2 mat\n",
|
|
" in\n",
|
|
" let vec = Vec.init (n_mo) (fun i ->\n",
|
|
" if List.mem i list\n",
|
|
" then 0.\n",
|
|
" else float_of_int(i))\n",
|
|
" in\n",
|
|
" let vec_list = Vec.to_list vec\n",
|
|
" in\n",
|
|
" let g a = int_of_float(a)\n",
|
|
" in\n",
|
|
" let vec_list_int = List.map g vec_list\n",
|
|
" \n",
|
|
" in\n",
|
|
" List.filter (fun x -> x > 0) vec_list_int;;\n",
|
|
"*) \n",
|
|
"\n",
|
|
" \n",
|
|
"\n",
|
|
"(*let tata = miss_elem toto;;\n",
|
|
"\n",
|
|
"let titi = [1.;2.]\n",
|
|
"\n",
|
|
"let f a = int_of_float(a);;\n",
|
|
"let test list = List.map f list;;\n",
|
|
"\n",
|
|
"test titi;;\n",
|
|
"*)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"let m_occ , m_vir = split_mat ran toto;;"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"let nocc = n_mo / 2;;\n",
|
|
"\n",
|
|
"(* Fonction de rassemblement de 2 matrices *)\n",
|
|
"let assemble = Mat.init_cols n_ao n_mo ( fun i j ->\n",
|
|
" if j > nocc \n",
|
|
" then m_vir.{i,j-nocc}\n",
|
|
" else m_occ.{i,j})\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"let tutu = List.init nocc (fun i -> i)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "OCaml 4.10.0",
|
|
"language": "OCaml",
|
|
"name": "ocaml-jupyter"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": "text/x-ocaml",
|
|
"file_extension": ".ml",
|
|
"mimetype": "text/x-ocaml",
|
|
"name": "OCaml",
|
|
"nbconverter_exporter": null,
|
|
"pygments_lexer": "OCaml",
|
|
"version": "4.10.0"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|