Python Forum
something that returns a linear function compatible with lognorm.pdf and lognorm.cdf?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
something that returns a linear function compatible with lognorm.pdf and lognorm.cdf?
#1

I'm trying to figure out how to make a lognorm function compatible with a linear function. Any ideas? Blush
Reply
#2
This doesn't seem like a generic Python question. Is it a math question? Or a question about (a) specific module(s)?
Reply
#3
It's a question about numpy and scipy. I'm using the lognorm function in scipy.stats, and I need to add a linear growth function. I was wondering if anyone knew a function I could use that would make this work. Here's my code:
import numpy as np
from scipy.stats import lognorm
import matplotlib.pyplot as plt
from math import exp


def runLognormal(start, current, mean, cumImpact, peakFactor):
    scale = exp(mean)
    return lognorm.pdf(current, peakFactor, start, scale)*cumImpact
    
def runLinear(start, stop, changePerQ, x):
    numIterations = (stop-start)*100
    y = np.array([])
    for x in range(start, stop):
        np.append(y, changePerQ)
    return y

     
x = np.linspace(0, 212, num=21200)
tax1 = runLognormal(92, x, 0.036, 0.071, 0.55)

label1 = runLinear(80, 160, 0.0006875, x)


############################################### GRAPH LABEL 1
fig, lbl1 = plt.subplots(1, 1)
label1X = np.linspace(80, 160, num = 8000)
lbl1.set_title('Text Based Labels')
lbl1.set_xlabel('Quarter')
lbl1.set_ylabel('Cumulative Effect')
lbl1.plot(label1X, runLinear(80, 160, 0.0006875, label1X))
##############################################################

veganGrowth = tax1 + label1

fig, ax = plt.subplots(1, 1)
ax.set_title('Instantaneous Rate of Change in Population')
ax.set_xlabel('$Quarter$')
ax.set_ylabel('$Population Omnivores$')
ax.plot(x, veganGrowth)
right now neither the graph of the linear function (it's supposed to return a straight line or the ax plot is working. I'm getting a 'x and y must have the same first dimension' error for both.

Error for Label graph:
Error:
File "<ipython-input-92-225e42a16155>", line 1, in <module> runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Main Program.py', wdir='C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction') File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile execfile(filename, namespace) File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc) File "C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Main Program.py", line 126, in <module> lbl1.plot(label1X, runLinear(80, 160, 0.0006875, label1X)) File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 1373, in plot for line in self._get_lines(*args, **kwargs): File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 304, in _grab_next_args for seg in self._plot_args(remaining, kwargs): File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 282, in _plot_args x, y = self._xy_from_xy(x, y) File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 223, in _xy_from_xy raise ValueError("x and y must have same first dimension") ValueError: x and y must have same first dimension
Error for the main graph with label graph commented out (note, in this version I took out about 50 iterations of the lognorm function, I know the problem is in the linear function because it graphs if I take that out)
Error:
Traceback (most recent call last): File "<ipython-input-101-225e42a16155>", line 1, in <module> runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Main Program.py', wdir='C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction') File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile execfile(filename, namespace) File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc) File "C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Main Program.py", line 133, in <module> veganGrowth = tax1 + tax2 + tax3 + tax4 + tax5 + tariff + ad1 + ad2 + ad3 + ad4 + ad5 + ad6 + ad7 + news1 + veg + veg2 + label1 + label2 ValueError: operands could not be broadcast together with shapes (21200,) (0,)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Most Compatible Text Editor to Handle Large Files? Robotguy 2 2,386 Aug-18-2020, 03:51 PM
Last Post: FortyTwo
  How to build linear regression by implementing Gradient Descent using only linear alg PythonSpeaker 1 2,194 Dec-01-2019, 05:35 PM
Last Post: Larz60+
  What is wrong with this implementation of the cost function for linear regression? JoeB 1 3,213 Dec-23-2017, 10:05 AM
Last Post: buran
  Runtime error when trying to graph using the lognorm function (2.7) Afterdarkreader 3 3,007 Dec-09-2017, 07:52 PM
Last Post: Afterdarkreader

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020