Commit 78ceee64 authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Add a function to directly load the pre-trained perceptron

parent e146909a
......@@ -2235,6 +2235,13 @@ of hidden layers/, their corresponding /sizes/, and the /learning
rate/.
#+end_deftypefun
#+attr_texinfo: :options {TarotPerceptron *} tarot_perceptron_static_default ()
#+begin_deftypefun
Allocate and return the best perceptron that the maintainer has been
able to learn. This perceptron is /static/, because no learning will
be remembered the next time you will call this function.
#+end_deftypefun
#+attr_texinfo: :options {TarotPerceptron *} tarot_perceptron_dup (const TarotPerceptron *@var{perceptron})
#+begin_deftypefun
Return an allocated copy of /perceptron/.
......@@ -2242,8 +2249,8 @@ Return an allocated copy of /perceptron/.
#+attr_texinfo: :options {void} tarot_perceptron_free (TarotPerceptron *@var{perceptron})
#+begin_deftypefun
Delete a /perceptron/ allocated by =tarot_perceptron_alloc= or
=tarot_perceptron_dup=.
Delete a /perceptron/ allocated by =tarot_perceptron_alloc=,
=tarot_perceptron_dup= or =tarot_perceptron_static_default=.
#+end_deftypefun
#+attr_texinfo: :options {void} tarot_perceptron_load (TarotPerceptron *@var{perceptron}, size_t @var{start}, size_t @var{nweights}, const double *@var{parameters})
......
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tarot 0.4.2.83-ebdc-dirty\n"
"Report-Msgid-Bugs-To: vivien@planete-kraus.eu\n"
"POT-Creation-Date: 2019-11-27 08:08+0100\n"
"POT-Creation-Date: 2019-11-27 08:13+0100\n"
"PO-Revision-Date: 2019-11-26 20:11+0100\n"
"Last-Translator: Vivien Kraus <vivien@planete-kraus.eu>\n"
"Language-Team: French\n"
......
......@@ -21,7 +21,11 @@ src_libtarot_libtarot_la_SOURCES += \
%reldir%/perceptron.c \
%reldir%/tarot/perceptron_private.h \
%reldir%/tarot/perceptron_private_impl.h \
%reldir%/tarot/perceptron_private_static_weights.h \
%reldir%/tarot/perceptron_private_static_structure.h \
%reldir%/julien/julien.h \
%reldir%/julien/julien.c
INTROSPECTED_SOURCES += %reldir%/perceptron.c %reldir%/julien/julien.c
INTROSPECTED_SOURCES += %reldir%/perceptron.c %reldir%/julien/julien.c \
%reldir%/tarot/perceptron_private_static_weights.h \
%reldir%/tarot/perceptron_private_static_structure.h
......@@ -33,6 +33,14 @@ tarot_perceptron_alloc (size_t n_hidden_layers, const size_t *hidden_sizes,
return ret;
}
TarotPerceptron *
tarot_perceptron_static_default ()
{
TarotPerceptron *ret = xmalloc (sizeof (TarotPerceptron));
perceptron_construct_static_default (ret);
return ret;
}
TarotPerceptron *
tarot_perceptron_dup (const TarotPerceptron * perceptron)
{
......
......@@ -39,6 +39,8 @@ extern "C"
*/
void tarot_perceptron_free (TarotPerceptron *perceptron);
TarotPerceptron *tarot_perceptron_static_default ();
TarotPerceptron * tarot_perceptron_dup (const TarotPerceptron *perceptron);
/**
......
......@@ -29,6 +29,8 @@ extern "C"
size_t n_hidden_layers,
const size_t *hidden_sizes,
double learning_rate);
static void perceptron_construct_static_default (TarotPerceptron *
perceptron);
static void perceptron_destruct (TarotPerceptron * perceptron);
static void perceptron_copy (TarotPerceptron * dest,
const TarotPerceptron * source);
......
......@@ -51,6 +51,21 @@ perceptron_construct (TarotPerceptron * perceptron,
perceptron->best_event.data = perceptron->event_data;
}
static inline void
perceptron_construct_static_default (TarotPerceptron * perceptron)
{
static const size_t hidden_sizes[] = {
#include "perceptron_private_static_structure.h"
};
static const double weights[] = {
#include "perceptron_private_static_weights.h"
};
size_t n_hidden_layers = sizeof (hidden_sizes) / sizeof (hidden_sizes[0]);
size_t n_weights = sizeof (weights) / sizeof (weights[0]);
perceptron_construct (perceptron, n_hidden_layers, hidden_sizes, 1e-6);
perceptron_load (perceptron, 0, n_weights, weights);
}
static inline void
perceptron_copy (TarotPerceptron * dest, const TarotPerceptron * source)
{
......
/* tarot implements the rules of the tarot game
* Copyright (C) 2019 Vivien Kraus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
7
/* tarot implements the rules of the tarot game
* Copyright (C) 2019 Vivien Kraus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
- 0.370031,
-72.162510, -0.484260, 2.505815, 5.475828, 30.025353, -11.545471, -1.830890,
0.329450, -5.569957, -0.181962, -0.497060, -1.283003, -0.486663, -1.228080,
1.443207, -0.375533, -23.376729, -9.305154, 2.796673, 0.608505, -0.900013,
-0.347947, -1.568535, 20.116732, -20.756046, 1.029525, -5.682657, 0.170159,
3.383301, -0.158209, 0.789395, -1.566093, 8.467498, -0.332631, -0.854602,
23.612455, 38.173840, 3.387373, 1.541771, 3.784640, 3.976931, 4.618627,
3.087788, 2.182127, -1.878332, 1.775055, 1.755528, -2.638043, 1.556124,
1.692240, -2.394060, -3.220677, 0.727159, -3.944821, -3.056076, -0.224777,
-0.156749, -2.136884, -12.291034, -3.629195, 0.252251, 5.327399, 1.916436,
2.323548, -0.907703, -1.747726, 2.859107, 3.675918, -1.779955, 2.278454,
2.076273, -1.526722, 1.099136, 1.685188, -1.571373, 1.164405, 0.643903,
-2.707451, 2.535956, 2.275963, -2.748607, -1.615138, 1.075858, -4.286305,
-1.277516, -0.656036, -2.313250, 2.790376, 3.412273, -6.856414, 1.741470,
3.619188, -1.790484, -0.827521, 2.554710, -2.391344, -0.331500, 1.774021,
-2.928523, 1.537278, 2.506898, -1.979319, 1.893177, 1.814965, -2.271251,
2.462657, 2.278584, -2.088121, 1.968794, 2.153996, -2.322073, 2.533911,
2.395539, -2.772732, 2.573049, 0.698459, -4.053904, 1.910806, 0.336042,
-1.361943, 2.481721, 1.826705, -2.003517, -3.363355, 2.656893, 1.816267,
-2.036356, 0.257433, 3.525994, 7.913187, 9.377227, -2.871088, -0.525254,
0.881421, 0.092897, -1.521442, 3.675043, 1.691633, 0.752114, -1.681813,
1.596731, 0.707650, 2.087917, -4.241497, -5.607981, 1.305109, -2.902593,
-4.750277, -2.902361, 11.563342, -10.769919, -0.151418, -8.247534, 0.528111,
0.150350, -0.477233, 0.026143, -1.337267, -2.081347, 0.044538, 0.560667,
-4.351214, 0.909586, 2.384021, -2.169554, 2.435383, 1.753659, -2.786324,
2.295895, 1.938860, -1.858216, 1.956083, 1.419456, -2.401806, 1.694226,
2.165373, -2.291515, -0.844158, -0.208176, -6.729273, 0.933429, -1.427812,
0.141297, 3.497162, 2.561894, -3.467972, 0.119298, 3.153423, 8.435973,
-101.709089, -12.351376, -3.245855, -29.034513, 49.044123, -8.365141,
1.959012, 2.073791, -5.842364, -1.767521, -8.603896, -10.444331, -9.779633,
-10.961674, -4.961710, -9.048095, -29.334537, -15.303420, -0.146796,
-0.158594, -0.998958, 0.546147, -0.692402, 71.336033, -76.134690, 4.175454,
-1.914632, 2.777744, -0.463348, -0.190732, -0.251998, 1.384702, -0.700912,
-0.610046, 3.387189, 13.860679, 19.359126, 0.462494, 1.051010, 3.410662,
4.502594, 8.653028, 3.020482, 2.182188, -2.358150, 2.026101, 2.198868,
-2.195045, 1.665133, 1.502485, -2.264523, -5.665902, -1.291904, -2.804257,
-1.649620, 0.830933, -0.014223, -4.865552, -7.645192, 1.840505, -0.001691,
4.093023, -0.816979, 11.266041, -1.262019, -0.033676, 2.574257, 5.373232,
-1.890803, 0.096242, 1.204267, -0.363413, -0.510385, 1.157433, 0.514720,
0.094695, -1.500732, -1.765197, 1.019226, 2.387198, -2.685030, -3.283685,
1.384749, -3.290561, -3.387866, -1.404942, -18.287041, 18.638635, 1.334279,
-2.090848, 0.427317, -0.655893, -0.964455, 0.213308, 1.069005, -3.311433,
0.011168, -0.302365, -1.535438, 2.619480, 2.642818, -2.287633, 2.127325,
2.490046, -1.927768, 2.139705, 2.190727, -2.406746, 2.704055, 2.144386,
-2.445067, 2.292945, 2.534777, -2.506322, 2.600947, 1.267984, -4.710931,
2.357939, -3.362070, 0.097904, 1.660782, 1.970529, -2.400673, -0.163043,
1.852963, -9.249830, -70.931155, -3.248598, 1.925904, 5.474196, 39.294106,
-6.606127, -0.559354, 0.524613, -2.229505, 0.434310, -4.188481, -4.213036,
-4.630736, -4.534207, 1.653363, -3.174042, -10.853076, -8.299988, 1.755949,
0.100950, -0.176606, -0.531217, -1.191077, -49.840620, 48.368871, 1.072325,
-5.222509, -1.147644, 1.703664, -0.698521, 0.828603, 1.529117, 7.860053,
-0.280342, -2.093334, -15.223504, 5.783174, 2.139316, -2.486618, 2.176701,
2.230764, -2.545687, 2.342864, 1.901199, -2.318548, 1.927817, 2.293907,
-2.463211, 2.142650, 2.574715, -2.320995, -1.231200, 0.397235, -1.992520,
-1.789488, -0.263082, 0.199196, 0.452861, -8.740189, -2.948119, 0.095336,
2.637613, -2.944435, -0.927496, 2.800102, -2.786716, 1.594671, 2.977513,
-3.504035, 2.006211, 1.795424, -1.985354, 2.037259, 2.375659, -2.686475,
0.122012, -2.027622, -2.724464, 1.693152, 2.562879, -4.553800, -2.432431,
-0.044938, -5.066433, -2.213011, -1.974635, -1.328735, 0.896179, 3.109219,
1.379544, 2.177365, 0.262934, -1.487357, -0.402934, 1.732521, -3.685509,
-0.403273, 2.776613, -1.788157, 2.709244, 2.260387, -1.851359, 2.144318,
1.983409, -2.468579, 2.541691, 1.906335, -2.410218, 2.410075, 2.337347,
-1.947353, 2.134905, 1.963297, -1.802416, 2.667897, -0.777949, -3.757093,
1.405780, 0.701227, -2.250205, 1.717738, 2.467695, -2.281224, 0.527143,
2.237051, -5.907020, 1.770998, 3.797658, -9.244483, -9.816049, 7.261895,
-0.863395
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment