Skip to main content

Anytime algorithms in Python

Project description


sudo -H pip3 install anytime



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]


    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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anytime-1.0.0.dev2.tar.gz (17.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page