Ask Your Question
1

Why doesn't the SageMath function find_local_maximum work for me in Python?

asked 4 years ago

user90664 gravatar image

The code below works in CoCalc, but I can't get it to run in Python in my IDE. I've imported numpy and sagemath, and referred to each as needed to define the math functions, but I can't get the find_local_maximum function to work. See below.

Code:

import numpy as np
import sagemath as sm

def mean_x(factor, values):
    return sum([np.cos(2*np.pi*v/factor) for v in values])/len(values)

def mean_y(factor, values):
    return sum([np.sin(2*np.pi*v/factor) for v in values])/len(values)

def calculatePeriodAppeal(factor, values):
    mx = mean_x(factor, values)
    my = mean_y(factor, values)
    appeal = np.sqrt(mx**2+my**2)
    return appeal

def calculateBestLinear(factor, values):
    mx = mean_x(factor, values).n()
    my = mean_y(factor, values).n()
    y0 = factor*np.atan2(my,mx)/(2*np.pi).n()
    err = 1-np.sqrt(mx**2+my**2).n()
    return [factor*x + y0, err]

def calculateGCDAppeal(factor, values):
    mx = mean_x(factor, values)
    my = mean_y(factor, values)
    appeal = 1 - np.sqrt((mx-1)**2+my**2)/2
    return appeal

testSeq = [552,827,275,809,534] 
gcd = calculateGCDAppeal(x, testSeq)
agcd = sm.find_local_maximum(gcd,20,30)
print(agcd)
np.plot(gcd,(x, 20,30))

Error:

Traceback (most recent call last):

  File "<ipython-input-163-fecb5397afab>", line 31, in <module>
    agcd = sm.find_local_maximum(gcd,20,30)

AttributeError: module 'sagemath' has no attribute 'find_local_maximum'
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 4 years ago

slelievre gravatar image

It would seem you ran pip install sagemath which installs the "sagemath" package from PyPI:

That is a dummy package and by doing that you did not install SageMath.

To access SageMath functionality you need to actually install SageMath, not the dummy "sagemath" package from PyPI.

Preview: (hide)
link

Comments

@slelievre I've now download and installed the .dmg file. The installation guide says to then "Simply use it." How do I use it in an IDE (Spyder or Jupyter notebook)?

user90664 gravatar imageuser90664 ( 4 years ago )

More on this as an answer to the follow-up dedicated question:

slelievre gravatar imageslelievre ( 4 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 4 years ago

Seen: 345 times

Last updated: Aug 28 '20