Anytime algorithms in Python
Project description
INSTALLATION:
sudo -H pip3 install anytimeUSAGE EXAMPLE:
""" The following example program gets a very large vector and tries to find the largest element in the vector. It stops after a pre-specified time, and returns the largest element found so far. """ import random, numpy as np from AnytimeAlgorithm2 import AnytimeAlgorithm class MaximumFinder(AnytimeAlgorithm): def __init__(self, vector): self.vector = vector self.currentMaximum = 0 def update(self): i = random.randint(0,len(self.vector)-1) if self.vector[i]>self.currentMaximum: self.currentMaximum = self.vector[i] print("self",self,"result",self.currentMaximum) def result(self): return self.currentMaximum v = np.random.rand(10000000) finder = MaximumFinder(v) print(finder.result_after(0.0001)) # seconds print(finder.result_after(0.001)) # seconds print(finder.result_after(0.01)) # seconds
Keywords: anytime algorithms Platform: UNKNOWN Classifier: Development Status :: 2 - Pre-Alpha Classifier: Intended Audience :: Developers Classifier: Topic :: Software Development Classifier: License :: OSI Approved :: GNU General Public License (GPL) Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file anytime-1.0.0.dev2.tar.gz
.
File metadata
- Download URL: anytime-1.0.0.dev2.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78729b0f80d4c7f3eeefc9001753208ba043500c9f3880f4110651364f25378f |
|
MD5 | 2e9ef73d59758e34cf0a0f0dd744a637 |
|
BLAKE2b-256 | d15a63bc58e729691e9b32c4a034ad451c320893623e8a305aba4da946c61e04 |