Biosensor Framework

Biosensor Framework: A C# Library for Affective Computing - Published in JOSS (2021)

https://github.com/munroe-meyer-institute-vr-laboratory/biosensor-framework

Science Score: 100.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org, zenodo.org
  • Committers with academic emails
  • Institutional organization owner
    Organization munroe-meyer-institute-vr-laboratory has institutional domain (www.unmc.edu)
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

affective-computing empatica-e4 microsoft-ml wesad
Last synced: 6 months ago · JSON representation ·

Repository

C# library that handles the full process of gathering biometric data from a body-worn sensor, transforming it into handcrafted feature vectors, and delivering an inferencing result in thirty-five lines of code.

Basic Info
Statistics
  • Stars: 7
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 2
Topics
affective-computing empatica-e4 microsoft-ml wesad
Created almost 5 years ago · Last pushed almost 4 years ago
Metadata Files
Readme License Citation Zenodo

README.md

status DOI

Biosensor Framework: A C# Library for Affective Computing

Parties Involved

Institution: Munroe Meyer Institute in the University of Nebraska Medical Center
Laboratory: Virtual Reality Laboratory
Advisor: Dr. James Gehringer
Developer: Walker Arce

Introduction

Developed in the Virtual Reality Laboratory at the Munroe Meyer Institute, this library provides an interface for interacting with biosensors and performing affective computing tasks on their output data streams. Currently, it natively supports the Empatica E4 and communicates through a TCP connection with their provided server.

This library provides the following capabilities: - Connection to the TCP client that Empatica provides for connecting their devices to a user's PC - Parsing and packing of commands to communicate bidirectionally with the TCP client - Collection and delivery of biometric readings to an end user's software application - Extraction of literature supported feature vectors to allow characterization of the biological signal features - Microsoft.ML support for inferencing on the feature vectors natively in C# in both multi-class and binary classification tasks - Support for simulating a data stream for debugging and testing applications without an Empatica E4 device - Support for parsing open source Empatica E4 datasets and training machine learning models on them (i.e. WESAD) - Support for interfacing new sensors into the same pipeline - Contains models trained on WESAD dataset in the Microsoft.ML framework

Motivation

For our lab to use biosensor data in our research projects, we needed an interface to pull in data from our Empatica E4, perform feature extraction, and return inferences from a trained model. From our research, there was no existing all in one library to do this and major parts of this project did not exist. Additionally, there was no Unity compatible way to process this data and perform actions from the output. From a programming perspective, it is best if there was no string manipulation when interacting with the server, so there needed to be a true wrapper for the TCP client communications. The development of the Biosensor Framework has allowed us to use these features reliably in all of our research projects. There will be errors about the loaded dependencies, though the project should still run with those present.

Dependencies

.NETStandard 2.0
    LightGBM (>= 2.2.3)
    MathNet.Numerics (>= 4.15.0)
    Microsoft.ML (>= 1.5.5)
    Microsoft.ML.FastTree (>= 1.5.5)
    Microsoft.ML.LightGbm (>= 1.5.5)

Installation

The library can be installed using the NuGet package manager and is listed publicly. For Unity, downloading the package and importing it through the Unity UI is the best approach. This includes all of the dependency libraries, a test script, a test scene, and an example output file. This example performs the same tasks as Example2 and needs to be supplied the E4 Streaming Server exe path, an output path, and your API key for your device.

The following command can be used to install the package using the NuGet CLI:

Install-Package Biosensor-Framework -Version 1.0.0

Unity Package

The included Unity package includes the required DLLs, a test script, and an example output file. To install the package, clone this repository and open the target Unity project.

Click on Assets -> Import Package -> Custom Package...

image

Navigate to the Unity Package folder and click on the "BiosensorFramework_Unity.unitypackage" file. When the file has loaded in, click "All" and "Import" to import the package into your project.

image

Testing Installation

Once the package has been installed, this repo can be cloned to get the test datasets and the trained models.
Follow Example 1 to test the functionality of the Empatica E4 TCP server communication and window data gathering.
Follow Example 2 to test the functionality of Microsoft.ML for affective computing tasks with a connected body-worn sensor.
Follow Example 3 to demonstrate the functionality of Microsoft.ML for affective computing tasks using the WESAD dataset without a connected body-worn sensor.

Basic Usage

This repository has two example projects. Example1 shows the basic usage to communicate with the server and pull data off of a biosensor. Example2 expands Example1 by adding in Microsoft.ML inferencing. Example2 will be used to explain the operation of the library.

``` using System; using System.Diagnostics; using System.IO; using System.Threading; using Microsoft.ML;

    using MMIVR.BiosensorFramework.Biosensors.EmpaticaE4;
    using MMIVR.BiosensorFramework.MachineLearningUtilities;

    namespace Example2_ComputingWithMicrosoftML
    {
        class Program
        {
            public static ServerClient Device1;
            static ServerClient client;
            public static MLContext mlContext;
            public static ITransformer Model;
            public static DataViewSchema ModelSchema;
            // TODO: Fill these out with your own values
            public static string APIKey = "";
            public static string ServerPath = @"";
            public static string WesadDirectory = @"";
            public static string SessionOutputPath = @"";
            public static string ModelDir = @"";

``` For each project, a client connection is established using the ServerClient class. This handles the TCP initialization, command communication, and error handling. Each device will have its own ServerClient instance, so Device1 is represented by a device name and a TCP connection. Additionally, the API key and the path to the server executable need to be defined. The API key can be found by following Empatica's directions from the Installation section. The path to the server is found in the installation directory for the server (i.e. @"{installation path}\EmpaticaBLEServer.exe").

Next the Microsoft.ML variables are created. static void Main(string[] args) { mlContext = new MLContext(); Train.RunBenchmarks(WesadDirectory, out ITransformer RegModel, out ITransformer MultiModel, out Model, ModelDir); In this example, the models are trained on the WESAD data using the RunBenchmarks function. The best performing models for each class are output. For this example, the binary classification model (BinModel) is used. ``` Console.WriteLine("E4 Console Interface - Press ENTER to begin the client"); Console.ReadKey();

        Console.WriteLine("Step 1 - Start Empatica server");
        Utilities.StartE4ServerGUI(ServerPath);

The E4 server is started through a Process call. This will open the GUI for the server, if that is not desired, the command line variant of the command can be called. client = new ServerClient(); Console.ReadKey(); client.StartClient(); Utilities.StartE4Server(ServerPath, APIKey); The E4 server can also be started through the command line variant as shown. Console.WriteLine("Step 2 - Getting connected E4 devices"); Utilities.ListDiscoveredDevices(client); Console.ReadKey();

        Console.WriteLine("     Available Devices:");
        Utilities.AvailableDevices.ForEach(i => Console.WriteLine("     Device Name: {0}", i));
        Console.ReadKey();

Listing the connected devices will show all devices connected through the Bluetooth dongle. These are managed internally. Device1 = new ServerClient(); Device1.StartClient(); Device1.DeviceName = Utilities.AvailableDevices[0]; Utilities.ConnectDevice(Device1); Console.ReadKey(); To connect a device, it needs to be assigned one of the available devices. Once that's done, the ConnectDevice function can be called and its TCP connection will be established. Utilities.SuspendStreaming(Device1); Since there are configurations to be done on the device, the streaming needs to be suspended. Console.WriteLine("Step 3 - Adding biometric data streams");

        foreach (ServerClient.DeviceStreams stream in Enum.GetValues(typeof(ServerClient.DeviceStreams)))
        {
            Thread.Sleep(100);
            Console.WriteLine("     Adding new stream: " + stream.ToString());
            Utilities.SubscribeToStream(Device1, stream);
        }

Each available device stream is assigned, but any number of streams can be assigned. Utilities.StartStreaming(Device1); var timer = Utilities.StartTimer(5); Utilities.WindowedDataReadyEvent += PullData;

        Console.WriteLine("ENTER to end program");
        Console.ReadKey();
    }

When the device has streaming restarted, it will begin collecting data as quickly as the server sends it. The window size for this example is 5 seconds, but can be any length. An internal timer will trigger an event at each expiration and then reset. Ending the program can be done by pressing the 'Enter' key. private static void PullData() { var watch = Stopwatch.StartNew(); var WindowData = Utilities.GrabWindow(Device1, @"C:\Readings.data"); var pred = Predict.PredictWindow(mlContext, Model, WindowData); watch.Stop(); Console.WriteLine("Time: {0} | Prediction: {1}", DateTime.Now, pred.Prediction); Console.WriteLine("Processing Time: {0}", watch.ElapsedMilliseconds); } ``` The data can be manipulated once the timer expires for the window size. The data can be grabbed by the GrabWindow function, which also can be fed a filepath to write the readings to a data file. Predictions can be done on the raw data using the PredictWindow function and a prediction is returned in a simple structure that contains the output bool.

Class Documentation

Biosensor Framework Documentation

Paper Citation

Arce, W., Gehringer, J., (2021). Biosensor Framework: A C# Library for Affective Computing. Journal of Open Source Software, 6(64), 3455, https://doi.org/10.21105/joss.03455

Contact

To address issues in the codebase, please create an issue in the repo and it will be addressed by a maintainer. For collaboration inquiries, please address Dr. James Gehringer (james.gehringer@unmc.edu). For technical questions, please address Walker Arce (walker.arce@unmc.edu).

Owner

  • Name: Munroe Meyer Institute Virtual Reality Laboratory
  • Login: Munroe-Meyer-Institute-VR-Laboratory
  • Kind: organization

The Virtual Reality Laboratory is researching how cutting-edge virtual reality technology can be applied to help our patients.

JOSS Publication

Biosensor Framework: A C# Library for Affective Computing
Published
August 06, 2021
Volume 6, Issue 64, Page 3455
Authors
Walker Arce ORCID
Virtual Reality Laboratory in the Munroe Meyer Institute at the University of Nebraska Medical Center
James Gehringer, ORCID
Virtual Reality Laboratory in the Munroe Meyer Institute at the University of Nebraska Medical Center
Editor
Øystein Sørensen ORCID
Tags
Affective Computing Biometrics Machine Learning Unity Microsoft.ML

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Arce"
  given-names: "Walker"
  orcid: "https://orcid.org/0000-0003-0819-0710"
- family-names: "Gehringer"
  given-names: "James"
  orcid: "https://orcid.org/0000-0003-3457-2288"
title: "Biosensor-Framework"
version: v1.0.0
date-released: 2021-08-04
url: "https://github.com/Munroe-Meyer-Institute-VR-Laboratory/Biosensor-Framework"
doi: 10.5281/zenodo.5159590

GitHub Events

Total
Last Year

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 114
  • Total Committers: 2
  • Avg Commits per committer: 57.0
  • Development Distribution Score (DDS): 0.009
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Walker Arce w****a@g****m 113
Dimitris Frangiadakis d****s@f****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: about 2 hours
  • Total issue authors: 0
  • Total pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • wsarce (1)
  • mitsosf (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads: unknown
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
nuget.org: biosensor-framework

Biosensor Framework is a C# library that handles the full process of gathering biometric data from a body-worn sensor, transforming it into handcrafted feature vectors, and delivering an inferencing result in thirty-five lines of code. Purpose built to handle the Empatica E4 biosensor, the Empatica provided TCP client is wrapped in a static C# class to provide convenient function calls and error handling to simplify code structure.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 13.8%
Average: 16.3%
Dependent packages count: 18.8%
Last synced: 6 months ago

Dependencies

BiosensorFramework/MMIVR.csproj nuget
  • Vsxmd 1.4.5 development
  • LightGBM 2.2.3
  • MathNet.Numerics 4.15.0
  • Microsoft.ML 1.5.5
  • Microsoft.ML.FastTree 1.5.5
  • Microsoft.ML.LightGbm 1.5.5
Example1_ServerInterfacingConsole/packages.config nuget
  • LightGBM 2.2.3
  • Microsoft.ML 1.5.5
  • Microsoft.ML.CpuMath 1.5.5
  • Microsoft.ML.DataView 1.5.5
  • Microsoft.ML.FastTree 1.5.5
  • Newtonsoft.Json 10.0.3
  • System.Buffers 4.4.0
  • System.CodeDom 4.4.0
  • System.Collections.Immutable 1.5.0
  • System.Memory 4.5.3
  • System.Numerics.Vectors 4.4.0
  • System.Reflection.Emit.Lightweight 4.3.0
  • System.Runtime.CompilerServices.Unsafe 4.5.3
  • System.Threading.Channels 4.7.1
  • System.Threading.Tasks.Extensions 4.5.4
Example2_ComputingWithMicrosoftML/packages.config nuget
  • LightGBM 2.2.3
  • MathNet.Numerics 4.15.0
  • Microsoft.ML 1.5.5
  • Microsoft.ML.CpuMath 1.5.5
  • Microsoft.ML.DataView 1.5.5
  • Microsoft.ML.FastTree 1.5.5
  • Microsoft.ML.LightGbm 1.5.5
  • Newtonsoft.Json 10.0.3
  • System.Buffers 4.4.0
  • System.CodeDom 4.4.0
  • System.Collections.Immutable 1.5.0
  • System.Memory 4.5.3
  • System.Numerics.Vectors 4.4.0
  • System.Reflection.Emit.Lightweight 4.3.0
  • System.Runtime.CompilerServices.Unsafe 4.5.3
  • System.Threading.Channels 4.7.1
  • System.Threading.Tasks.Extensions 4.5.4
Example3_ComputingWithoutAnE4/packages.config nuget
  • LightGBM 2.2.3
  • MathNet.Numerics 4.15.0
  • Microsoft.ML 1.5.5
  • Microsoft.ML.CpuMath 1.5.5
  • Microsoft.ML.DataView 1.5.5
  • Microsoft.ML.FastTree 1.5.5
  • Microsoft.ML.LightGbm 1.5.5
  • Newtonsoft.Json 10.0.3
  • System.Buffers 4.4.0
  • System.CodeDom 4.4.0
  • System.Collections.Immutable 1.5.0
  • System.Memory 4.5.3
  • System.Numerics.Vectors 4.4.0
  • System.Reflection.Emit.Lightweight 4.3.0
  • System.Runtime.CompilerServices.Unsafe 4.5.3
  • System.Threading.Channels 4.7.1
  • System.Threading.Tasks.Extensions 4.5.4