-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from behrica/generateTests
Auto generate tests
- Loading branch information
Showing
11 changed files
with
130 additions
and
982 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,6 @@ temp | |
*.qmd | ||
book | ||
|
||
/.clj-kondo/ | ||
test/noj_book/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(ns gen-tests | ||
(:require | ||
[scicloj.clay.v2.api :as clay] | ||
[clojure.java.io :as io] | ||
[clojure.string :as str])) | ||
|
||
(defn do-generate-tests [] | ||
(->> | ||
(file-seq (io/file "notebooks/noj_book")) | ||
(filter #(str/ends-with? (.toPath %) ".clj")) | ||
(run! | ||
#(let [p (.getAbsolutePath %)] | ||
(println :generate-tests p) | ||
(clay/make! {:source-path p | ||
:show false})))) | ||
(shutdown-agents)) | ||
|
||
(clay/make! {:source-path "notebooks/noj_book/automl.clj" :show false}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(ns lr | ||
(:require [tablecloth.api :as tc] | ||
[tech.v3.tensor :as dt] | ||
[scicloj.metamorph.ml :as ml] | ||
[scicloj.ml.smile.regression] | ||
[scicloj.metamorph.ml.loss :as loss] | ||
[tech.v3.dataset.modelling :as dsmod] | ||
[tech.v3.dataset.tensor :as dst] | ||
[tech.v3.dataset :as ds] | ||
[tech.v3.datatype.functional :as dtf])) | ||
|
||
(def x (dt/->tensor [[1 1] [1 2] [2 2] [2 3]])) | ||
(def y | ||
(dtf/+ 3 | ||
(dt/reduce-axis x (fn [row] (dtf/dot-product row (dt/->tensor [1 2])))))) | ||
|
||
(def y-ds | ||
(-> | ||
(dst/tensor->dataset x) | ||
(tc/add-column :y y) | ||
(dsmod/set-inference-target :y))) | ||
|
||
(def reg | ||
(ml/train y-ds | ||
{:model-type :smile.regression/ordinary-least-square})) | ||
|
||
(- 1 (loss/rmse y (:y (ml/predict y-ds reg))));; => 1.0 | ||
(seq (.coefficients (ml/thaw-model reg))) ;; => (2.9999999999999996 0.9999999999999998 2.0000000000000004) | ||
(seq (:y (ml/predict (tc/dataset [[3 5]]) reg)));; => (16.0) | ||
|
||
|
||
(defn Xy->dataset | ||
"Combines tensor X and vector y to a dataset | ||
where y is set to be the inference target | ||
x need to be a tensor | ||
y a seq or 1-D tensor | ||
" | ||
[x y] | ||
|
||
(-> | ||
(dst/tensor->dataset x) | ||
(ds/add-column (ds/new-column :y y)) | ||
(dsmod/set-inference-target :y))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.