|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "9bea9844-da81-4bcc-922e-743f62a968aa", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import numpy as np\n", |
| 11 | + "import matplotlib.pyplot as plt\n", |
| 12 | + "import piecewise_regression \n", |
| 13 | + "#pip install piecewise-regression \n", |
| 14 | + "#https://github.com/chasmani/piecewise-regression.git\n", |
| 15 | + "\n", |
| 16 | + "x = np.load(\"your_file.npy\")\n", |
| 17 | + "y = np.load(\"your_file.npy\")\n", |
| 18 | + "\n", |
| 19 | + "plt.plot(x, y, \"o-\")\n", |
| 20 | + "plt.xlabel('x_label')\n", |
| 21 | + "plt.ylabel('y_label')\n", |
| 22 | + "plt.title('Knee method to sovle for Tg')\n", |
| 23 | + "\n", |
| 24 | + "pw_fit = piecewise_regression.Fit(x, y, n_breakpoints=1)\n", |
| 25 | + "pw_fit.plot_breakpoints(color='r')\n", |
| 26 | + "\n", |
| 27 | + "\n", |
| 28 | + "def find_tg(x,y):\n", |
| 29 | + " results=pw_fit.get_results()\n", |
| 30 | + " Tg=results['estimates']['breakpoint1']['estimate']\n", |
| 31 | + " return Tg\n", |
| 32 | + "\n", |
| 33 | + "Tg=find_tg(x,y)\n", |
| 34 | + "print('Glass transition temperature is:',Tg)\n", |
| 35 | + "\n", |
| 36 | + "def find_slope1(x,y):\n", |
| 37 | + " results=pw_fit.get_results()\n", |
| 38 | + " slope1=results['estimates']['alpha1']['estimate']\n", |
| 39 | + " return slope1\n", |
| 40 | + "\n", |
| 41 | + "slope1=find_slope1(x,y)\n", |
| 42 | + "print('Slope before breakpoint1 is:',slope1)\n", |
| 43 | + "\n", |
| 44 | + "def find_slope2(x,y):\n", |
| 45 | + " results=pw_fit.get_results()\n", |
| 46 | + " slope2=results['estimates']['beta1']['estimate']\n", |
| 47 | + " return slope2\n", |
| 48 | + "\n", |
| 49 | + "slope2=find_slope2(x,y)\n", |
| 50 | + "print('Slope after breakpoint1 is:',slope2)\n", |
| 51 | + "\n", |
| 52 | + "# Print a summary of the fit\n", |
| 53 | + "pw_fit.summary()" |
| 54 | + ] |
| 55 | + } |
| 56 | + ], |
| 57 | + "metadata": { |
| 58 | + "kernelspec": { |
| 59 | + "display_name": "Python 3 (ipykernel)", |
| 60 | + "language": "python", |
| 61 | + "name": "python3" |
| 62 | + }, |
| 63 | + "language_info": { |
| 64 | + "codemirror_mode": { |
| 65 | + "name": "ipython", |
| 66 | + "version": 3 |
| 67 | + }, |
| 68 | + "file_extension": ".py", |
| 69 | + "mimetype": "text/x-python", |
| 70 | + "name": "python", |
| 71 | + "nbconvert_exporter": "python", |
| 72 | + "pygments_lexer": "ipython3", |
| 73 | + "version": "3.12.3" |
| 74 | + } |
| 75 | + }, |
| 76 | + "nbformat": 4, |
| 77 | + "nbformat_minor": 5 |
| 78 | +} |
0 commit comments