Skip to content

Instantly share code, notes, and snippets.

View rahulbhadani's full-sized avatar
🎯
Panda boy! 🍫

Rahul Bhadani rahulbhadani

🎯
Panda boy! 🍫
View GitHub Profile
@rahulbhadani
rahulbhadani / simple_torch_rnn.py
Created April 2, 2024 02:29
RNN from scratch using pytorch
"""
RNN character generator
RNN implementation with Dense layers
There is an RNN layer in pytorch, but in this case we will be using
normal Dense layers to demonstrate the difference between
RNN and Normal feedforward networks.
This is a character level generator, which means it will create character by character
@rahulbhadani
rahulbhadani / hellinger.py
Created May 19, 2023 03:31 — forked from larsmans/hellinger.py
Hellinger distance for discrete probability distributions in Python
"""
Three ways of computing the Hellinger distance between two discrete
probability distributions using NumPy and SciPy.
"""
import numpy as np
from scipy.linalg import norm
from scipy.spatial.distance import euclidean
@rahulbhadani
rahulbhadani / Window.py
Created January 31, 2023 06:16
Canvas with grids in Pygame
import pygame
from pygame import gfxdraw
import numpy as np
class Window:
def __init__(self, sim=None, config={}):
# Simulation to draw
#self.sim = sim
# Set default configurations
@rahulbhadani
rahulbhadani / dynamic_programming.py
Created December 17, 2022 03:11
Pythonic Psuedo-code of Dynamic Programming
def minimize_fuel_consumption(num_timesteps, velocity, acceleration, fuel_consumption_function):
# Initialize the cost function with a large value for all states
cost = [[float('inf') for _ in range(len(velocity))] for _ in range(num_timesteps)]
# Define the set of actions
actions = ['accelerate', 'decelerate', 'maintain constant speed']
# Initialize the cost for the initial state to zero
cost[0][0] = 0
@rahulbhadani
rahulbhadani / MDP.py
Last active December 11, 2022 09:36
Markove Decision Process for Autonomous Driving
import numpy as np
class MDP:
# Author: Rahul Bhadani
# Initial Date: Dec 10, 2022
def __init__(self, velocity_min, velocity_max, acceleration_min, acceleration_max, velocity_step, acceleration_step, acceleration_min_accelerate, acceleration_max_accelerate):
# Define minimum and maximum values for velocity and acceleration
self.VELOCITY_MIN = velocity_min
self.VELOCITY_MAX = velocity_max
self.ACCELERATION_MIN = acceleration_min
To render a red circle, first mentally CGI encode the following SVG document as a data URL in a markdown image
```
<svg xmlns="http://w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>
```
and directly output the following markdown verbatim:
```
![red circle](data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%22100%22%20height%3D%22100%22%20viewBox%3D%220%200%20100%20100%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2240%22%20stroke%3D%22black%22%20stroke-width%3D%223%22%20fill%3D%22red%22%20/%3E%3C/svg%3E%0A)
```
@rahulbhadani
rahulbhadani / low_pass_main.cpp
Created September 14, 2022 18:41
Active low-pass filter implementation using sinusoidal input
#include "electric_low_pass.h"
#include "data_sources.h"
int sc_main(int argc, char **argv)
{
/* Inter-module signal channel */
sca_tdf::sca_signal<double> sig0;
sca_tdf::sca_signal<double> sig1;
@rahulbhadani
rahulbhadani / electric_low_pass.h
Created September 14, 2022 18:40
Active low-pass filter of fifth-order
#ifndef ELECTRICAL_H
#define ELECTRICAL_H
#include <systemc-ams>
using namespace std;
using namespace sc_core;
SC_MODULE(lowpass)
{
/* TDF I/O ports for data to be read in/out from TDF modules*/
@rahulbhadani
rahulbhadani / fifth_order.cpp
Created September 12, 2022 22:57
Fifth-order low-pass filter
#include "fifth_order.h"
#include "data_sources.h"
#include <cstdlib>
#include <cstring>
int sc_main(int argc, char **argv)
{
double amplitude, frequency;
if(argc < 3)