new initialization method
This commit is contained in:
		
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										74
									
								
								EvolutionaryAlgorithm/ea_tools.ipynb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								EvolutionaryAlgorithm/ea_tools.ipynb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,74 @@ | |||||||
|  | { | ||||||
|  |  "nbformat": 4, | ||||||
|  |  "nbformat_minor": 2, | ||||||
|  |  "metadata": { | ||||||
|  |   "language_info": { | ||||||
|  |    "name": "python", | ||||||
|  |    "codemirror_mode": { | ||||||
|  |     "name": "ipython", | ||||||
|  |     "version": 3 | ||||||
|  |    } | ||||||
|  |   }, | ||||||
|  |   "orig_nbformat": 2, | ||||||
|  |   "file_extension": ".py", | ||||||
|  |   "mimetype": "text/x-python", | ||||||
|  |   "name": "python", | ||||||
|  |   "npconvert_exporter": "python", | ||||||
|  |   "pygments_lexer": "ipython3", | ||||||
|  |   "version": 3 | ||||||
|  |  }, | ||||||
|  |  "cells": [ | ||||||
|  |   { | ||||||
|  |    "cell_type": "markdown", | ||||||
|  |    "execution_count": null, | ||||||
|  |    "metadata": {}, | ||||||
|  |    "outputs": [], | ||||||
|  |    "source": [ | ||||||
|  |     "# Statistical Tools" | ||||||
|  |    ] | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "cell_type": "code", | ||||||
|  |    "execution_count": 1, | ||||||
|  |    "metadata": {}, | ||||||
|  |    "outputs": [], | ||||||
|  |    "source": [ | ||||||
|  |     "import numpy as np" | ||||||
|  |    ] | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "cell_type": "markdown", | ||||||
|  |    "execution_count": null, | ||||||
|  |    "metadata": {}, | ||||||
|  |    "outputs": [], | ||||||
|  |    "source": [ | ||||||
|  |     "* Helper function to calculate the wheel of fortune" | ||||||
|  |    ] | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "cell_type": "code", | ||||||
|  |    "execution_count": 2, | ||||||
|  |    "metadata": {}, | ||||||
|  |    "outputs": [], | ||||||
|  |    "source": [ | ||||||
|  |     "def wheel_of_fortune(rank_i,n):\n", | ||||||
|  |     "    return rank_i / (0.5 * n * (n + 1))" | ||||||
|  |    ] | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "cell_type": "code", | ||||||
|  |    "execution_count": 3, | ||||||
|  |    "metadata": {}, | ||||||
|  |    "outputs": [], | ||||||
|  |    "source": [ | ||||||
|  |     "def wheel_of_fortune_selection(items: list, item_scores:list):\n", | ||||||
|  |     "    ordering = np.argsort(item_scores)\n", | ||||||
|  |     "    ordering = ordering + 1\n", | ||||||
|  |     "\n", | ||||||
|  |     "    wheel_weights = wheel_of_fortune(ordering, len(ordering))\n", | ||||||
|  |     "\n", | ||||||
|  |     "    return np.random.choice(items, p=wheel_weights)\n" | ||||||
|  |    ] | ||||||
|  |   } | ||||||
|  |  ] | ||||||
|  | } | ||||||
							
								
								
									
										22
									
								
								EvolutionaryAlgorithm/ea_tools.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								EvolutionaryAlgorithm/ea_tools.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | |||||||
|  | #!/usr/bin/env python3 | ||||||
|  | # coding: utf-8 | ||||||
|  |  | ||||||
|  | # # Statistical Tools | ||||||
|  |  | ||||||
|  | import numpy as np | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # * Helper function to calculate the wheel of fortune | ||||||
|  |  | ||||||
|  | def wheel_of_fortune(rank_i,n): | ||||||
|  |     return rank_i / (0.5 * n * (n + 1)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def wheel_of_fortune_selection(items: list, item_scores:list): | ||||||
|  |     ordering = np.argsort(item_scores) | ||||||
|  |     ordering = ordering + 1 | ||||||
|  |  | ||||||
|  |     wheel_weights = wheel_of_fortune(ordering, len(ordering)) | ||||||
|  |  | ||||||
|  |     return np.random.choice(items, p=wheel_weights) | ||||||
|  |  | ||||||
		Reference in New Issue
	
	Block a user