Giter VIP home page Giter VIP logo

pangadfs's People

Contributors

deepsource-autofix[bot] avatar deepsourcebot avatar erictruett-dotcom avatar sansbacon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pangadfs's Issues

Complete framework for transformers

Complete framework for transformers - convert projections from various sources and lineups from pydfs-lineup-optimizer for use in pangadfs by 11/22/2020.

Cannot import name GeneticAlgorithm from pangadfs

Here is my code:
from pathlib import Path
from pangadfs import GeneticAlgorithm
import numpy as np
import logging

ctx = {
    'ga_settings': {
        'csvpth': Path(__file__).parent.parent / 'appdata' / 'pool.csv',
        'n_generations': 20,
        'population_size': 30000,
        'stop_criteria': 10,
        'verbose': True
    },

    'site_settings': {
        'flex_positions': ('RB', 'WR', 'TE'),
        'lineup_size': 9,
        'posfilter': {'QB': 14, 'RB': 8, 'WR': 8, 'TE': 5, 'DST': 4, 'FLEX': 8},
        'posmap': {'DST': 1, 'QB': 1, 'TE': 1, 'RB': 2, 'WR': 3, 'FLEX': 7},
        'salary_cap': 50000
    }
}

# set up GeneticAlgorithm object
ga = GeneticAlgorithm()

# create pool and pospool
pop_size = ctx['ga_settings']['population_size']
pool = ga.pool(csvpth=ctx['ga_settings']['csvpth'])
posfilter = ctx['site_settings']['posfilter']
flex_positions = ctx['site_settings']['flex_positions']
pospool = ga.pospool(pool=pool, posfilter=posfilter, column_mapping={}, flex_positions=flex_positions)

# create salary and points arrays
points = pool[cmap['proj']].values
salaries = pool[cmap['salary']].values

# create initial population
initial_population = ga.populate(
    pospool=pospool, 
    posmap=ctx['site_settings']['posmap'], 
    population_size=pop_size
)

# apply validators (default are salary and duplicates)
initial_population = ga.validate(
    population=initial_population, 
    salaries=salaries,
    salary_cap=ctx['site_settings']['salary_cap']
)

population_fitness = ga.fitness(
    population=initial_population, 
    points=points
)

# set overall_max based on initial population
omidx = population_fitness.argmax()
best_fitness = population_fitness[omidx]
best_lineup = initial_population[omidx]

# create new generations
n_unimproved = 0
population = initial_population.copy()

for i in range(1, ctx['ga_settings']['n_generations'] + 1):

    # end program after n generations if not improving
    if n_unimproved == ctx['ga_settings']['stop_criteria']:
        break

    # display progress information with verbose parameter
    if ctx['ga_settings'].get('verbose'):
        logging.info(f'Starting generation {i}')
        logging.info(f'Best lineup score {best_fitness}')

    # select the population
    # here, we are holding back the fittest 20% to ensure
    # that crossover and mutation do not overwrite good individuals
    elite = ga.select(
        population=population, 
        population_fitness=population_fitness, 
        n=len(population) // ctx['ga_settings'].get('elite_divisor', 5),
        method='fittest'
    )

    selected = ga.select(
        population=population, 
        population_fitness=population_fitness, 
        n=len(population),
        method='roulette'
    )

    # cross over the population
    crossed_over = ga.crossover(population=selected, method='uniform')

    # mutate the crossed over population (leave elite alone)
    mutated = ga.mutate(population=crossed_over, mutation_rate=.05)

    # validate the population (elite + mutated)
    population = ga.validate(
        population=np.vstack((elite, mutated)), 
        salaries=salaries, 
        salary_cap=ctx['site_settings']['salary_cap']
    )

    # assess fitness and get the best score
    population_fitness = ga.fitness(population=population, points=points)
    omidx = population_fitness.argmax()
    generation_max = population_fitness[omidx]

    # if new best score, then set n_unimproved to 0
    # and save the new best score and lineup
    # otherwise increment n_unimproved
    if generation_max > best_fitness:
        logging.info(f'Lineup improved to {generation_max}')
        best_fitness = generation_max
        best_lineup = population[omidx]
        n_unimproved = 0
    else:
        n_unimproved += 1
        logging.info(f'Lineup unimproved {n_unimproved} times')

# show best score and lineup at conclusion
print(pool.loc[best_lineup, :])
print(f'Lineup score: {best_fitness}')

Here is the stack trace:
panga(spyder)

Release version 0.2

Release version 0.2 by 2/1/2021. The only predicate at this point is completing documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.