crocrodile.nn - Neural Network

Crocrodile Neural Network.

Base class for Crocrodile NN.

class crocrodile.nn.NeuralNetwork[source]

Base class for NN.

static array_to_csv(array, csv_path)[source]

Write array in csv_path CSV file.

calculate() numpy.ndarray[source]

Calculate NN result by using :attr:NeuralNetwork.layers with multiple layers.

Returns

Output layer.

Return type

numpy.ndarray

change_files()[source]

Change files locations.

check_always_same()[source]

Check success rating on good moves and on bad moves.

check_difference()[source]

Check success rate on good moves and on bad moves and return it.

check_move(board, move)[source]

Generate inputs, calculate and return output.

check_test()[source]

Check NN on test dataset.

check_train()[source]

Check NN on train dataset.

clear() None[source]

Clear layers.

static csv_to_array(csv_path)[source]

Read CSV file and return array.

full_calculate()[source]

Calculate NN result with all hidden layers.

generate() None[source]

Generate new matrixes.

generate_inputs(board: str, move: str) bool[source]

Generate inputs for move move in board.

Parameters
  • board (str) – FEN of the board.

  • move (str) – UCI notation of the move to check.

Returns

False if this is a check, True else.

Return type

bool

genetic_configure()[source]

Configure genetic training algorithm.

genetic_random()[source]

Random NNs for genetic algorithm.

genetic_save(confirmation=True)[source]

Save genetic algorithm configuration.

genetic_train()[source]

Genetic training algorithm.

New training algorithm using a real genetic algorithm.

load_layers(nn: int) None[source]

Load layers with a NN ID from nns/.

Parameters

nn (int) – NN to load (nns/<nn>-….csv)

Returns

Nothing.

Return type

None

load_networks() None[source]

Load networks from folder nns/

Returns

None

Return type

None

masters_check_train()[source]

Check NN on train dataset.

masters_genetic_train(masters_good_moves, masters_bad_moves, config)[source]

Genetic training algorithm.

New training algorithm using a real genetic algorithm.

masters_random()[source]

Random NNs for genetic masters training algorithm.

static normalisation(array)[source]

Normalisation.

old_calculate()[source]

Calculate NN result.

output()[source]

Return NN output.

test(list_good_moves: list, list_bad_moves: list) tuple[int][source]

Test neural network. Used by basics training.

Parameters
  • list_good_moves (list) – List of good moves at format [“<FEN>n<Good move>”, “<FEN>n<Good move>”]

  • list_bad_moves (list) – List of bad moves at format [“<FEN>n<Bad move>”, “<FEN>n<Bad move>”]

Returns

Tupple (Number of correct answers on good moves, Number of correct answers on bad moves)

Return type

tuple[int]

test_full(list_good_moves: list, list_bad_moves: list, sub=False, good_moves_data=0, bad_moves_data=0) Tuple[int, int][source]

Test neural network on full files. Lists list_good_moves and list_bad_moves can be obtained from training files with open(“<path>”).read().split(”nn”). Standard format is [“<FEN>n<move>”, “<FEN>n<move>”]

Parameters
  • list_good_moves (list) – List of good moves at standard format

  • list_bad_moves (list) – List of bad moves at standard format

Returns

Number of correct answers on good moves, on bad moves

Return type

Tuple[int, int]

test_full_multiprocesses(list_good_moves: list, list_bad_moves: list) Tuple[int, int][source]

Test neural network on full files with multi-processing. Lists list_good_moves and list_bad_moves can be obtained from training files with open(“<path>”).read().split(”nn”). Standard format is [“<FEN>n<move>”, “<FEN>n<move>”]

Parameters
  • list_good_moves (list) – List of good moves at standard format

  • list_bad_moves (list) – List of bad moves at standard format

Returns

Number of correct answers on good moves, on bad moves

Return type

Tuple[int, int]

test_new(new_good_move: str, new_bad_moves: list) Tuple[int, int][source]

Test neural network on new moves new_good_move and new_bad_moves. Standard format is [“<FEN>n<move>”, “<FEN>n<move>”] Standard format for new_good_move is “<FEN>n<move>”

Parameters
  • list_good_moves (list) – The new good move to test at standard format

  • list_bad_moves (list) – The new bad moves to test at standard format

Returns

Total number of correct answers on good moves, on bad moves

Return type

Tuple[int, int]

train()[source]

Train Neural Network.

crocrodile.nn.basics_train - Basics Training

Crocrodile Training.

Back to basics.

author

Virinas-code and ZeBox

class crocrodile.nn.basics_train.BasicsTrain[source]

Basics train - class for training Crocrodile.

Author

@ZeBox and Virinas-code

static array_to_csv(array, csv_path)[source]

Write array in csv_path CSV file.

ask() dict[source]

Ask for inputs.

Parameters

self (BasicsTrain) – Current BasicsTrain object.

Returns

Good moves file.

Return type

str

couple(matrix1: numpy.ndarray, matrix2: numpy.ndarray) numpy.ndarray[source]

Couple two matrixes.

Parameters
  • matrix1 (numpy.ndarray) – First matrix to couple.

  • matrix2 (numpy.ndarray) – Second matrix to couple.

Returns

A new matrix.

Return type

numpy.ndarray

couple_networks(worst_network: int, network1: int, network2: int) None[source]

Couple two networks.

Parameters
  • network1 (int) – First network indice

  • network2 (int) – Second network indice.

Returns

Nothing.

Return type

None.

couple_pawns(matrix1: numpy.ndarray, matrix2: numpy.ndarray) numpy.ndarray[source]

Couple two pawn matrixes.

Parameters
  • matrix1 (numpy.ndarray) – First matrix to couple.

  • matrix2 (numpy.ndarray) – Second matrix to couple.

Returns

A new matrix.

Return type

numpy.ndarray

couple_pieces(matrix1: numpy.ndarray, matrix2: numpy.ndarray) numpy.ndarray[source]

Couple two pieces matrixes.

Parameters
  • matrix1 (numpy.ndarray) – First matrix to couple.

  • matrix2 (numpy.ndarray) – Second matrix to couple.

Returns

A new matrix.

Return type

numpy.ndarray

generate() None[source]

Generate empty networks and save them.

Returns

None

Return type

None

static generate_bad_moves(good_move_pos: str, good_moves_list, bad_moves_list)[source]

Generate bad moves for position.

Parameters

good_move_pos (str) – Good move in position (FEN + good move)

load() None[source]

Load neural networks from nns/ folder.

Returns

None

main(argv)[source]

Start training.

static parse_good_moves(good_moves_file: str) list[source]

Parse good moves in good_moves_file. good_moves_file is only a file path.

Parameters

good_moves_file (str) – Path to the good moves file.

Returns

The list of FENs + good move.

Return type

list

save() None[source]

Save neural networks to nns/ folder.

Returns

None

train(new_good_move: str, new_bad_moves: str, param_good_moves: list, param_bad_moves: list) float[source]

Train neural networks.

Returns

Mean performance at end.

Return type

float

crocrodile.nn.basics_train.main(argv)[source]

Start function called in init.

Parameters

argv (list) – sys.argv

Returns

None

Return type

None

crocrodile.nn.load_network - Load Network

Crocrodile NNs.

Load network: Load network to use it with the client.

crocrodile.nn.masters_train - Masters Training

crocrodile.nn.nn_auto - Auto Neural Network Training

NN Auto.

Simple tool to create Crocrodile NN Training files.

crocrodile.nn.nn_random - Random Neural Networks Generator

crocrodile.nn.old_nn - Old Neural Network