(* Fit *)let data = [ ([ 1.0; 2.0 ], 1.0); ... ] inlet tree =Regression_tree.fit data ~max_depth:10in
print_endline (Regression_tree.to_string tree ~indent:4);
(* Predict *)let x = (List.hd data |> fst) in
print_endline (Regression_tree.predict tree x |> string_of_float)(* Fit *)let data = [ ([ 1.0; 2.0 ], 1.0); ... ] inlet regressor =Gradient_boosting_regressor.fit data ~n_estimators:8~learning_rate:0.1inlet improved_regressor =Gradient_boosting_regressor.boost regressor [...]
(* Predict *)let x = (List.hd data |> fst) in
print_endline (Gradient_boosting_regressor.predict regressor x |> string_of_float)letdata : (float, float) Dataset.single = [ ([ 1.0; 2.0 ], 1.0); ... ] inlet load_dataset =let csv =Csv.load "data/Auto.csv"inDataset.single_of_csv [ 4 ] 5 csvC/Objective-C bindings to Apple Metal Performance Shaders.
C/Objective-C bindings to higher-level Metal Performance Shaders Graph API. This is used for automatic gradient computation in Tensors.
let graph =Mps_graph.create ()inlet tensor_a =Mps_graph.placeholder graph [ 4 ] inlet tensor_b =Mps_graph.placeholder graph [ 4 ] inlet data_a =Mps_graph.Tensor_data.create [ 1.; 2.; 3.; 4. ] [ 4 ] inlet data_b =Mps_graph.Tensor_data.create [ 10.; 20.; 30.; 40. ] [ 4 ] inlet tensor_result =Mps_graph.add tensor_a tensor_b inlet data_result =Mps_graph.Tensor_data.zeroes [ 4 ] inMps_graph.run_forward_backward_with_feeds graph feeds;
let result =Mps_graph.Tensor_data.to_list data_e inList.iter (Printf.printf "%f ") result;
Printf.printf "\n";First iteration of binding directly to lower-level Metal and MPS primitives. PoC-only.
let device =Mtl.Device.create_system_default inlet command_queue =Mtl.CommandQueue.make device inlet buffer_a =Mtl.Buffer.of_data device [| 1.; 2.; 3.; 4. |] inlet buffer_b =Mtl.Buffer.of_data device [| 5.; 6.; 7.; 8. |] inlet buffer_c =Mtl.Buffer.of_length device 4inlet descriptor_a =Mps.MatrixDescriptor.create ~rows:2~columns:2~row_bytes:8inlet descriptor_b =Mps.MatrixDescriptor.create ~rows:2~columns:2~row_bytes:8inlet descriptor_c =Mps.MatrixDescriptor.create ~rows:2~columns:2~row_bytes:8inlet matrix_a =Mps.Matrix.of_buffer ~descriptor:descriptor_a ~buffer:buffer_a inlet matrix_b =Mps.Matrix.of_buffer ~descriptor:descriptor_b ~buffer:buffer_b inlet matrix_c =Mps.Matrix.of_buffer ~descriptor:descriptor_c ~buffer:buffer_c inlet kernel =Mps.Kernel.MatrixMultiplication.alloc ~transpose_left:false~transpose_right:false~rows:2~columns:2~inner_dim:2~alpha:1.0~beta:0.0 device inlet command_buffer =Mtl.CommandBuffer.make command_queue inMps.Kernel.MatrixMultiplication.encode kernel ~left_matrix:matrix_a ~right_matrix:matrix_b ~result_matrix:matrix_c command_buffer;
Mtl.CommandBuffer.commit command_buffer;
Mtl.CommandBuffer.wait_until_completed command_buffer;
let result =Mtl.Buffer.to_float_array buffer_c in
...let a =Tensor.{ value = [|2.0|] } |>Tensor.to_device Autograd.Device.Mpsinlet b =Tensor.{ value = [|3.0|] } |>Tensor.to_device Autograd.Device.Mpsinlet product = mul a b in
print_endline (product |>Tensor.to_device Autograd.Device.Cpu|>Tensor.to_string);