Code Monkey home page Code Monkey logo

Comments (5)

sg-s avatar sg-s commented on August 30, 2024

This is clearly the way to go:

#include <functional>
#include <string>
#include <cmath>
#include <iostream>

using namespace std;

class channel {

int p = 3;
int q = 1;
public:
	string name = "unset";

	double E = 50;
	double g = 0;
	double gbar = 0;

	std::function<double(double)> m_inf;

	channel(double gbar, double E, int p, int q) {
		this->gbar = gbar;
		this->E = E;
		this->p = p;
		this->q = q;
	}

};


namespace prinz {
	double NaV_m_inf(double V) {
		return 1.0/(1.0+exp((V+25.5)/-5.29));
	}
}



int main() {

	channel NaV = channel(100,50,3,1);
	NaV.m_inf = prinz::NaV_m_inf;

	cout << "NaV.m_inf(30) = " << NaV.m_inf(-50) << endl;

}

and we can use the namespace keyword to namespace our channels!

from xolotl.

sg-s avatar sg-s commented on August 30, 2024

This allows for a much richer type heirarchy:

  • a catch-all conductance class
  • a VoltageGatedInactivating class, for e.g., NaV
  • a VoltageGatedActivating class for e.g., Kd
  • a CalciumGated class for e.g., KCa
  • synapses are just conductances that connect to two compartments

Note the m_inf can have different type signatures for each, because conductance doesn't need to know anything about activation functions

from xolotl.

sg-s avatar sg-s commented on August 30, 2024

unfortunately MATLAB doesn't support this:


Did not add member 'm_inf' to class 'channel' at channel_test.hpp:20.
  'std::function<double(double)>' as data member or return type not supported.

Did not add member 'h_inf' to class 'channel' at channel_test.hpp:21.
  'std::function<double(double)>' as data member or return type not supported.

from xolotl.

alec-hoyland avatar alec-hoyland commented on August 30, 2024

Damn you, two language problem!

from xolotl.

sg-s avatar sg-s commented on August 30, 2024

but wait! there's a workaround:

if one writes a setter method, everything is cool

void set_m_inf(string);

and together with a wrapper method that calls m_inf and other dynamically dispatched functions, it mostly mitigates this issue

from xolotl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.