Skip to content

Instantly share code, notes, and snippets.

@TheBojda
TheBojda / pygad_reinforcement.py
Created January 24, 2021 09:41
Reinforcement learning with genetic algorithm (PyGAD and OpenAI Gym - CartPole-v1)
import gym
import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import pygad.kerasga
import pygad
def fitness_func(solution, sol_idx):
global keras_ga, model, observation_space_size, env
@TheBojda
TheBojda / pygad_reinforcement.ipynb
Last active December 22, 2022 14:57
PyGAD (Genetic Algorithm) reinforcement learning example with Tensorflow and OpenAI Gym (CartPole v1)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@TheBojda
TheBojda / cifar10.py
Created August 24, 2020 08:14
PyTorch CIFAR10 neural network example
import torch
import torchvision
import torchvision.transforms as transforms
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import matplotlib.pyplot as plt
import torch.optim as optim
transform = transforms.Compose([
@TheBojda
TheBojda / autograd.py
Created August 23, 2020 13:07
Simple linear regression with PyTorch autograd
import torch
import numpy as np
import matplotlib.pyplot as plt
TRUE_W = 3.0
TRUE_b = 0.5
NUM_EXAMPLES = 1000
x = torch.empty(NUM_EXAMPLES).normal_(mean=0,std=1.0)
@TheBojda
TheBojda / todo-native.vue
Created June 10, 2020 10:44
Simple Vue Native TODO example with NativeBase components
<template>
<nb-container>
<nb-header></nb-header>
<nb-grid>
<nb-row :style="{ height: 60 }" v-for="(todo, idx) in todos" :key="idx">
<nb-col :size="85" :style="{ justifyContent: 'center' }">
<text :style="{marginLeft: 10}">{{todo}}</text>
</nb-col>
<nb-col :size="15" :style="{ justifyContent: 'center' }">
<nb-button iconCenter transparent :on-press="() => removeItem(idx)">
@TheBojda
TheBojda / todo_host.html
Created May 29, 2020 11:47
Vue.js TODO component host file example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Vue.js TODO Example</title>
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/http-vue-loader"></script>
</head>
<body>
@TheBojda
TheBojda / todo.vue
Created May 29, 2020 09:54
TODO component in Vue.js
<template>
<table>
<tr v-for="(todo, idx) in todos" :key="idx">
<td class="todo_text">{{todo}}</td>
<td>
<button @click="removeItem(idx)">Done</button>
</td>
</tr>
<tr>
<td>
@TheBojda
TheBojda / vue_todo.html
Created May 29, 2020 09:31
Simple Vue.js TODO app
<!DOCTYPE html>
<html lang="en">
<head>
<title>Vue.js TODO Example</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
@TheBojda
TheBojda / vue.html
Created May 29, 2020 07:33
Simple Vue.js example
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<span>{{msg}}</span><button @click="btnClick">Push me!</button>
</div>
<script>
new Vue({
@TheBojda
TheBojda / jquery.html
Created May 29, 2020 07:08
Simple jQuery example
<html>
<head>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
</head>
<body>
<span id="msg">Hello World!</span><button id="btn">Push me!</button>
<script>
$('#btn').click(function() {
$('#msg').html('Hello jQuery!');
});