Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View gugarosa's full-sized avatar
🔓
Code should be young, wild and free.

Gustavo de Rosa gugarosa

🔓
Code should be young, wild and free.
View GitHub Profile
@gugarosa
gugarosa / penalized_objective.py
Created June 14, 2021 14:57
Penalizes an Opytimizer objective function with a more complex constraint.
import numpy as np
from opytimizer import Opytimizer
from opytimizer.functions import ConstrainedFunction
from opytimizer.optimizers.swarm import PSO
from opytimizer.spaces import SearchSpace
# Defines a customized objective function
def spfunc(x):
# Just a mock-up objective to emulate the problem
@gugarosa
gugarosa / compare_sets_pokemons.py
Last active January 3, 2021 16:39
Creates an array for comparing whether certain Pokémon exists or not in a TCG set.
import numpy as np
import pandas as pd
from pokemontcgsdk import Card, Set
# Sets to be searched
SETS = ['g1', 'sm1', 'sm2', 'sm4', 'sm6', 'sm7',
'sm11', 'sm12', 'swsh1', 'swsh2', 'swsh3', 'swsh4']
# Instantiates an array of cards from all sets
cards_sets = np.zeros((894, len(SETS)))
@gugarosa
gugarosa / host_scripting.sh
Last active October 8, 2019 20:29
Logs into a host via SSH, runs a command and dumps the file to local machine via SFTP.
#!/bin/bash
# User to enter the host
USER=username
# Script to run in host
# In this case, we will be dumping the process my memory usage order
SCRIPT="ps aux --sort -%mem"
# List of hosts
@gugarosa
gugarosa / plot_3d_function.m
Created August 30, 2019 15:12
It creates a 3D plot of a pre-defined mathematical function.
% Function to be plotted
z = @(x,y) (sin(x) * sqrt(x)) * (sin(y) * sqrt(y));
% Plots the function
h = fsurf(z,[0 10]);
% Defines some attributes on its positioning and brightness
camlight(110,70)
brighten(0.7)
h.EdgeColor = 'none';
@gugarosa
gugarosa / optimize.py
Last active November 14, 2023 13:27
A t-SNE perplexity's parameter optimization through meta-heuristics. It uses NALP for loading word embeddings and Opytimizer for performing the optimization.
from opytimizer import Opytimizer
from opytimizer.core.function import Function
from opytimizer.optimizers.abc import ABC
from opytimizer.spaces.search import SearchSpace
from sklearn.manifold import TSNE
import word2vec
# Loading word2vec word embeddings
w2v = word2vec.load_word_vectors()
@gugarosa
gugarosa / simulated_annealing.py
Created June 18, 2019 13:35
A Simulated Annealing algorithm for function optimization.
from math import pi, sin
import numpy as np
def function(x):
"""Fitness function.
Args:
x (float): Input value for fitness function.
@gugarosa
gugarosa / hill_climbing.py
Created June 18, 2019 13:34
A set of Hill Climbing and its variants for function optimization.
from math import pi, sin
import numpy as np
def function(x):
"""Fitness function.
Args:
x (float): Input value for fitness function.
@gugarosa
gugarosa / aco.py
Last active June 18, 2019 14:05
An Ant Colony Optimization for the Travel Salesman problem.
import numpy as np
import utils as u
class ACO:
"""An Ant-Colony Optimization implementation.
"""
@gugarosa
gugarosa / mnist_mosaic.m
Created May 30, 2019 12:19
It supposes that you have a pre-loaded MNIST matrix and creates a mosaic of random samples.
% Check this repository to create your own MNIST Matlab's matrix
% https://github.com/daniel-e/mnist_octave/
% Loading MNIST matrix file
load('mnist.mat');
% Creating an empty array of 100 samples
A = zeros(28, 28, 1, 100, 'uint8');
% Looping through 100 random samples
@gugarosa
gugarosa / youtube_channel_scrapper.py
Last active February 23, 2019 16:06
Requests the source code of a youtube channel page and scraps any data you need from it.
import time
import requests
from bs4 import BeautifulSoup
# Youtube channel URL
url = 'https://www.youtube.com/channel/UCTCykZFeSbgMuL2ZzhSyVzg'
# Sleeping time
sleep_time = 5