Training Models using Federated Learning (Part 3)

Through the first 2 parts of our federated learning demo project, we created a client-server application in Python using socket programming. In part 1, the client-server application was able to handle only a single connection at a time. In other words, the server was able to only receive a single message from the client per connection.

Federated Learning Demo in Python (Part 1): Client-Server Application

Implementing a client-server application using socket programming

heartbeat.fritz.ai

In part 2, we extended the application was extended to allow multiple messages to be sent within the same connection. The server can handle multiple connections simultaneously:

Federated Learning Demo in Python (Part 2): Multiple Connections using Threading

Enabling our server to receive multiple incoming connections

heartbeat.fritz.ai

The code for this project is available at the Federated Learning GitHub project under the TutorialProject directory.

In this tutorial, we’ll create a machine learning model (neural network) will using a library named PyGAD at the server. But the model actually won’t be trained at the server. Instead, the model will be sent to the connected clients where it will be trained by each client’s local data. PyGAD uses a genetic algorithm for training these models.

Each client sends its version of the model back to the server. The server aggregates the parameters of all models to create a single model. Such a model is then tested to make sure it has an acceptable accuracy/error.

In case the model needs further training using the clients’ local data, the model will be sent back to the clients where its parameters are tuned, and finally sent back to the server. The process continues until the model does performs sufficiently well on the test data.

The code for this tutorial is available in the Federated Learning GitHub project under the TutorialProject/Part3 directory. Future tutorials will build upon this application.

Here are the sections covered in this tutorial:

  • Installing PyGAD
  • Creating a population of neural networks using PyGAD
  • Sending the population to connected clients
  • Receiving the population at the client
  • Training the network using the genetic algorithm
  • Sending the client’s trained network back to the server
  • Final client code
  • Aggregating models’ parameters at the server
  • Final server code
  • Running the server and the clients

Let’s get started.

Installing PyGAD

PyGAD is an open-source Python library for building genetic algorithms (GA). It supports many parameters that customize GA for various problems.

PyGAD is available via PyPI, and thus it can be installed using the pip installer. For Windows, use the following CMD command:

pip install pygad

For Linux and Mac, replace pip by pip3 (PyGAD uses Python 3):

pip3 install pygad

Once installed, make sure it works correctly by importing it. The latest version at the time of writing this tutorial is 2.3.0.

import pygad
​
print(pygad.__version__)

If everything is working properly, then we can proceed into the next section to create a neural network using PyGAD.

Creating a Population of Neural Networks using PyGAD

PyGAD uses a GA for training machine learning models. Currently, the models it supports are neural networks and convolutional neural networks.

The GA starts with a random initial population of solutions for the problem being optimized. For some generations, the solutions are evolved by applying mutation and crossover. PyGAD creates an initial population of networks using its pygad.gann module. In this section, we’ll discuss how to use this module for creating the initial population of networks.

The pygad.gann module has a class named GANN. Check the documentation of this module in in the official docs. An instance of this class represents a population of neural networks. All the neural networks have the same architecture. Later, this population will be evolved using the genetic algorithm.

The constructor of the pygad.gann.GANN class accepts the following parameters:

  • num_solutions: Population size (i.e. number of solutions in the population).
  • num_neurons_input: Number of input layer neurons.
  • num_neurons_output: Number of output layer neurons.
  • num_neurons_hidden_layers=[]: A list representing the number of neurons in the hidden layer. If the list has N elements, then it will have N hidden layers. The number of neurons for the hidden layers are specified according to the list values.
  • output_activation="softmax": A string representing the activation function in the output layer.
  • hidden_activations="relu": A string or list of strings representing the activation function in the hidden layer(s). If a list is specified, then its length must be equal to the length of the num_neurons_hidden_layers parameter.

For more information about these parameters, check out the documentation.

The problem that will be modeled in this tutorial is the XOR problem. The samples for this problem are listed below. For each sample, there are 2 inputs and 1 output. Thus, the num_neurons_input parameter will be set to 2, and the num_neurons_output will be set to 1.

#artificial-intelligence #python #heartbeat #machine-learning #federated-learning #deep learning

What is GEEK

Buddha Community

Training Models using Federated Learning (Part 3)

Training Models using Federated Learning (Part 3)

Through the first 2 parts of our federated learning demo project, we created a client-server application in Python using socket programming. In part 1, the client-server application was able to handle only a single connection at a time. In other words, the server was able to only receive a single message from the client per connection.

Federated Learning Demo in Python (Part 1): Client-Server Application

Implementing a client-server application using socket programming

heartbeat.fritz.ai

In part 2, we extended the application was extended to allow multiple messages to be sent within the same connection. The server can handle multiple connections simultaneously:

Federated Learning Demo in Python (Part 2): Multiple Connections using Threading

Enabling our server to receive multiple incoming connections

heartbeat.fritz.ai

The code for this project is available at the Federated Learning GitHub project under the TutorialProject directory.

In this tutorial, we’ll create a machine learning model (neural network) will using a library named PyGAD at the server. But the model actually won’t be trained at the server. Instead, the model will be sent to the connected clients where it will be trained by each client’s local data. PyGAD uses a genetic algorithm for training these models.

Each client sends its version of the model back to the server. The server aggregates the parameters of all models to create a single model. Such a model is then tested to make sure it has an acceptable accuracy/error.

In case the model needs further training using the clients’ local data, the model will be sent back to the clients where its parameters are tuned, and finally sent back to the server. The process continues until the model does performs sufficiently well on the test data.

The code for this tutorial is available in the Federated Learning GitHub project under the TutorialProject/Part3 directory. Future tutorials will build upon this application.

Here are the sections covered in this tutorial:

  • Installing PyGAD
  • Creating a population of neural networks using PyGAD
  • Sending the population to connected clients
  • Receiving the population at the client
  • Training the network using the genetic algorithm
  • Sending the client’s trained network back to the server
  • Final client code
  • Aggregating models’ parameters at the server
  • Final server code
  • Running the server and the clients

Let’s get started.

Installing PyGAD

PyGAD is an open-source Python library for building genetic algorithms (GA). It supports many parameters that customize GA for various problems.

PyGAD is available via PyPI, and thus it can be installed using the pip installer. For Windows, use the following CMD command:

pip install pygad

For Linux and Mac, replace pip by pip3 (PyGAD uses Python 3):

pip3 install pygad

Once installed, make sure it works correctly by importing it. The latest version at the time of writing this tutorial is 2.3.0.

import pygad
​
print(pygad.__version__)

If everything is working properly, then we can proceed into the next section to create a neural network using PyGAD.

Creating a Population of Neural Networks using PyGAD

PyGAD uses a GA for training machine learning models. Currently, the models it supports are neural networks and convolutional neural networks.

The GA starts with a random initial population of solutions for the problem being optimized. For some generations, the solutions are evolved by applying mutation and crossover. PyGAD creates an initial population of networks using its pygad.gann module. In this section, we’ll discuss how to use this module for creating the initial population of networks.

The pygad.gann module has a class named GANN. Check the documentation of this module in in the official docs. An instance of this class represents a population of neural networks. All the neural networks have the same architecture. Later, this population will be evolved using the genetic algorithm.

The constructor of the pygad.gann.GANN class accepts the following parameters:

  • num_solutions: Population size (i.e. number of solutions in the population).
  • num_neurons_input: Number of input layer neurons.
  • num_neurons_output: Number of output layer neurons.
  • num_neurons_hidden_layers=[]: A list representing the number of neurons in the hidden layer. If the list has N elements, then it will have N hidden layers. The number of neurons for the hidden layers are specified according to the list values.
  • output_activation="softmax": A string representing the activation function in the output layer.
  • hidden_activations="relu": A string or list of strings representing the activation function in the hidden layer(s). If a list is specified, then its length must be equal to the length of the num_neurons_hidden_layers parameter.

For more information about these parameters, check out the documentation.

The problem that will be modeled in this tutorial is the XOR problem. The samples for this problem are listed below. For each sample, there are 2 inputs and 1 output. Thus, the num_neurons_input parameter will be set to 2, and the num_neurons_output will be set to 1.

#artificial-intelligence #python #heartbeat #machine-learning #federated-learning #deep learning

A Wrapper for Sembast and SQFlite to Enable Easy

FHIR_DB

This is really just a wrapper around Sembast_SQFLite - so all of the heavy lifting was done by Alex Tekartik. I highly recommend that if you have any questions about working with this package that you take a look at Sembast. He's also just a super nice guy, and even answered a question for me when I was deciding which sembast version to use. As usual, ResoCoder also has a good tutorial.

I have an interest in low-resource settings and thus a specific reason to be able to store data offline. To encourage this use, there are a number of other packages I have created based around the data format FHIR. FHIR® is the registered trademark of HL7 and is used with the permission of HL7. Use of the FHIR trademark does not constitute endorsement of this product by HL7.

Using the Db

So, while not absolutely necessary, I highly recommend that you use some sort of interface class. This adds the benefit of more easily handling errors, plus if you change to a different database in the future, you don't have to change the rest of your app, just the interface.

I've used something like this in my projects:

class IFhirDb {
  IFhirDb();
  final ResourceDao resourceDao = ResourceDao();

  Future<Either<DbFailure, Resource>> save(Resource resource) async {
    Resource resultResource;
    try {
      resultResource = await resourceDao.save(resource);
    } catch (error) {
      return left(DbFailure.unableToSave(error: error.toString()));
    }
    return right(resultResource);
  }

  Future<Either<DbFailure, List<Resource>>> returnListOfSingleResourceType(
      String resourceType) async {
    List<Resource> resultList;
    try {
      resultList =
          await resourceDao.getAllSortedById(resourceType: resourceType);
    } catch (error) {
      return left(DbFailure.unableToObtainList(error: error.toString()));
    }
    return right(resultList);
  }

  Future<Either<DbFailure, List<Resource>>> searchFunction(
      String resourceType, String searchString, String reference) async {
    List<Resource> resultList;
    try {
      resultList =
          await resourceDao.searchFor(resourceType, searchString, reference);
    } catch (error) {
      return left(DbFailure.unableToObtainList(error: error.toString()));
    }
    return right(resultList);
  }
}

I like this because in case there's an i/o error or something, it won't crash your app. Then, you can call this interface in your app like the following:

final patient = Patient(
    resourceType: 'Patient',
    name: [HumanName(text: 'New Patient Name')],
    birthDate: Date(DateTime.now()),
);

final saveResult = await IFhirDb().save(patient);

This will save your newly created patient to the locally embedded database.

IMPORTANT: this database will expect that all previously created resources have an id. When you save a resource, it will check to see if that resource type has already been stored. (Each resource type is saved in it's own store in the database). It will then check if there is an ID. If there's no ID, it will create a new one for that resource (along with metadata on version number and creation time). It will save it, and return the resource. If it already has an ID, it will copy the the old version of the resource into a _history store. It will then update the metadata of the new resource and save that version into the appropriate store for that resource. If, for instance, we have a previously created patient:

{
    "resourceType": "Patient",
    "id": "fhirfli-294057507-6811107",
    "meta": {
        "versionId": "1",
        "lastUpdated": "2020-10-16T19:41:28.054369Z"
    },
    "name": [
        {
            "given": ["New"],
            "family": "Patient"
        }
    ],
    "birthDate": "2020-10-16"
}

And we update the last name to 'Provider'. The above version of the patient will be kept in _history, while in the 'Patient' store in the db, we will have the updated version:

{
    "resourceType": "Patient",
    "id": "fhirfli-294057507-6811107",
    "meta": {
        "versionId": "2",
        "lastUpdated": "2020-10-16T19:45:07.316698Z"
    },
    "name": [
        {
            "given": ["New"],
            "family": "Provider"
        }
    ],
    "birthDate": "2020-10-16"
}

This way we can keep track of all previous version of all resources (which is obviously important in medicine).

For most of the interactions (saving, deleting, etc), they work the way you'd expect. The only difference is search. Because Sembast is NoSQL, we can search on any of the fields in a resource. If in our interface class, we have the following function:

  Future<Either<DbFailure, List<Resource>>> searchFunction(
      String resourceType, String searchString, String reference) async {
    List<Resource> resultList;
    try {
      resultList =
          await resourceDao.searchFor(resourceType, searchString, reference);
    } catch (error) {
      return left(DbFailure.unableToObtainList(error: error.toString()));
    }
    return right(resultList);
  }

You can search for all immunizations of a certain patient:

searchFunction(
        'Immunization', 'patient.reference', 'Patient/$patientId');

This function will search through all entries in the 'Immunization' store. It will look at all 'patient.reference' fields, and return any that match 'Patient/$patientId'.

The last thing I'll mention is that this is a password protected db, using AES-256 encryption (although it can also use Salsa20). Anytime you use the db, you have the option of using a password for encryption/decryption. Remember, if you setup the database using encryption, you will only be able to access it using that same password. When you're ready to change the password, you will need to call the update password function. If we again assume we created a change password method in our interface, it might look something like this:

class IFhirDb {
  IFhirDb();
  final ResourceDao resourceDao = ResourceDao();
  ...
    Future<Either<DbFailure, Unit>> updatePassword(String oldPassword, String newPassword) async {
    try {
      await resourceDao.updatePw(oldPassword, newPassword);
    } catch (error) {
      return left(DbFailure.unableToUpdatePassword(error: error.toString()));
    }
    return right(Unit);
  }

You don't have to use a password, and in that case, it will save the db file as plain text. If you want to add a password later, it will encrypt it at that time.

General Store

After using this for a while in an app, I've realized that it needs to be able to store data apart from just FHIR resources, at least on occasion. For this, I've added a second class for all versions of the database called GeneralDao. This is similar to the ResourceDao, but fewer options. So, in order to save something, it would look like this:

await GeneralDao().save('password', {'new':'map'});
await GeneralDao().save('password', {'new':'map'}, 'key');

The difference between these two options is that the first one will generate a key for the map being stored, while the second will store the map using the key provided. Both will return the key after successfully storing the map.

Other functions available include:

// deletes everything in the general store
await GeneralDao().deleteAllGeneral('password'); 

// delete specific entry
await GeneralDao().delete('password','key'); 

// returns map with that key
await GeneralDao().find('password', 'key'); 

FHIR® is a registered trademark of Health Level Seven International (HL7) and its use does not constitute an endorsement of products by HL7®

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add fhir_db

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  fhir_db: ^0.4.3

Alternatively, your editor might support or flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:fhir_db/dstu2.dart';
import 'package:fhir_db/dstu2/fhir_db.dart';
import 'package:fhir_db/dstu2/general_dao.dart';
import 'package:fhir_db/dstu2/resource_dao.dart';
import 'package:fhir_db/encrypt/aes.dart';
import 'package:fhir_db/encrypt/salsa.dart';
import 'package:fhir_db/r4.dart';
import 'package:fhir_db/r4/fhir_db.dart';
import 'package:fhir_db/r4/general_dao.dart';
import 'package:fhir_db/r4/resource_dao.dart';
import 'package:fhir_db/r5.dart';
import 'package:fhir_db/r5/fhir_db.dart';
import 'package:fhir_db/r5/general_dao.dart';
import 'package:fhir_db/r5/resource_dao.dart';
import 'package:fhir_db/stu3.dart';
import 'package:fhir_db/stu3/fhir_db.dart';
import 'package:fhir_db/stu3/general_dao.dart';
import 'package:fhir_db/stu3/resource_dao.dart'; 

example/lib/main.dart

import 'package:fhir/r4.dart';
import 'package:fhir_db/r4.dart';
import 'package:flutter/material.dart';
import 'package:test/test.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  final resourceDao = ResourceDao();

  // await resourceDao.updatePw('newPw', null);
  await resourceDao.deleteAllResources(null);

  group('Playing with passwords', () {
    test('Playing with Passwords', () async {
      final patient = Patient(id: Id('1'));

      final saved = await resourceDao.save(null, patient);

      await resourceDao.updatePw(null, 'newPw');
      final search1 = await resourceDao.find('newPw',
          resourceType: R4ResourceType.Patient, id: Id('1'));
      expect(saved, search1[0]);

      await resourceDao.updatePw('newPw', 'newerPw');
      final search2 = await resourceDao.find('newerPw',
          resourceType: R4ResourceType.Patient, id: Id('1'));
      expect(saved, search2[0]);

      await resourceDao.updatePw('newerPw', null);
      final search3 = await resourceDao.find(null,
          resourceType: R4ResourceType.Patient, id: Id('1'));
      expect(saved, search3[0]);

      await resourceDao.deleteAllResources(null);
    });
  });

  final id = Id('12345');
  group('Saving Things:', () {
    test('Save Patient', () async {
      final humanName = HumanName(family: 'Atreides', given: ['Duke']);
      final patient = Patient(id: id, name: [humanName]);
      final saved = await resourceDao.save(null, patient);

      expect(saved.id, id);

      expect((saved as Patient).name?[0], humanName);
    });

    test('Save Organization', () async {
      final organization = Organization(id: id, name: 'FhirFli');
      final saved = await resourceDao.save(null, organization);

      expect(saved.id, id);

      expect((saved as Organization).name, 'FhirFli');
    });

    test('Save Observation1', () async {
      final observation1 = Observation(
        id: Id('obs1'),
        code: CodeableConcept(text: 'Observation #1'),
        effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
      );
      final saved = await resourceDao.save(null, observation1);

      expect(saved.id, Id('obs1'));

      expect((saved as Observation).code.text, 'Observation #1');
    });

    test('Save Observation1 Again', () async {
      final observation1 = Observation(
          id: Id('obs1'),
          code: CodeableConcept(text: 'Observation #1 - Updated'));
      final saved = await resourceDao.save(null, observation1);

      expect(saved.id, Id('obs1'));

      expect((saved as Observation).code.text, 'Observation #1 - Updated');

      expect(saved.meta?.versionId, Id('2'));
    });

    test('Save Observation2', () async {
      final observation2 = Observation(
        id: Id('obs2'),
        code: CodeableConcept(text: 'Observation #2'),
        effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
      );
      final saved = await resourceDao.save(null, observation2);

      expect(saved.id, Id('obs2'));

      expect((saved as Observation).code.text, 'Observation #2');
    });

    test('Save Observation3', () async {
      final observation3 = Observation(
        id: Id('obs3'),
        code: CodeableConcept(text: 'Observation #3'),
        effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
      );
      final saved = await resourceDao.save(null, observation3);

      expect(saved.id, Id('obs3'));

      expect((saved as Observation).code.text, 'Observation #3');
    });
  });

  group('Finding Things:', () {
    test('Find 1st Patient', () async {
      final search = await resourceDao.find(null,
          resourceType: R4ResourceType.Patient, id: id);
      final humanName = HumanName(family: 'Atreides', given: ['Duke']);

      expect(search.length, 1);

      expect((search[0] as Patient).name?[0], humanName);
    });

    test('Find 3rd Observation', () async {
      final search = await resourceDao.find(null,
          resourceType: R4ResourceType.Observation, id: Id('obs3'));

      expect(search.length, 1);

      expect(search[0].id, Id('obs3'));

      expect((search[0] as Observation).code.text, 'Observation #3');
    });

    test('Find All Observations', () async {
      final search = await resourceDao.getResourceType(
        null,
        resourceTypes: [R4ResourceType.Observation],
      );

      expect(search.length, 3);

      final idList = [];
      for (final obs in search) {
        idList.add(obs.id.toString());
      }

      expect(idList.contains('obs1'), true);

      expect(idList.contains('obs2'), true);

      expect(idList.contains('obs3'), true);
    });

    test('Find All (non-historical) Resources', () async {
      final search = await resourceDao.getAll(null);

      expect(search.length, 5);
      final patList = search.toList();
      final orgList = search.toList();
      final obsList = search.toList();
      patList.retainWhere(
          (resource) => resource.resourceType == R4ResourceType.Patient);
      orgList.retainWhere(
          (resource) => resource.resourceType == R4ResourceType.Organization);
      obsList.retainWhere(
          (resource) => resource.resourceType == R4ResourceType.Observation);

      expect(patList.length, 1);

      expect(orgList.length, 1);

      expect(obsList.length, 3);
    });
  });

  group('Deleting Things:', () {
    test('Delete 2nd Observation', () async {
      await resourceDao.delete(
          null, null, R4ResourceType.Observation, Id('obs2'), null, null);

      final search = await resourceDao.getResourceType(
        null,
        resourceTypes: [R4ResourceType.Observation],
      );

      expect(search.length, 2);

      final idList = [];
      for (final obs in search) {
        idList.add(obs.id.toString());
      }

      expect(idList.contains('obs1'), true);

      expect(idList.contains('obs2'), false);

      expect(idList.contains('obs3'), true);
    });

    test('Delete All Observations', () async {
      await resourceDao.deleteSingleType(null,
          resourceType: R4ResourceType.Observation);

      final search = await resourceDao.getAll(null);

      expect(search.length, 2);

      final patList = search.toList();
      final orgList = search.toList();
      patList.retainWhere(
          (resource) => resource.resourceType == R4ResourceType.Patient);
      orgList.retainWhere(
          (resource) => resource.resourceType == R4ResourceType.Organization);

      expect(patList.length, 1);

      expect(patList.length, 1);
    });

    test('Delete All Resources', () async {
      await resourceDao.deleteAllResources(null);

      final search = await resourceDao.getAll(null);

      expect(search.length, 0);
    });
  });

  group('Password - Saving Things:', () {
    test('Save Patient', () async {
      await resourceDao.updatePw(null, 'newPw');
      final humanName = HumanName(family: 'Atreides', given: ['Duke']);
      final patient = Patient(id: id, name: [humanName]);
      final saved = await resourceDao.save('newPw', patient);

      expect(saved.id, id);

      expect((saved as Patient).name?[0], humanName);
    });

    test('Save Organization', () async {
      final organization = Organization(id: id, name: 'FhirFli');
      final saved = await resourceDao.save('newPw', organization);

      expect(saved.id, id);

      expect((saved as Organization).name, 'FhirFli');
    });

    test('Save Observation1', () async {
      final observation1 = Observation(
        id: Id('obs1'),
        code: CodeableConcept(text: 'Observation #1'),
        effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
      );
      final saved = await resourceDao.save('newPw', observation1);

      expect(saved.id, Id('obs1'));

      expect((saved as Observation).code.text, 'Observation #1');
    });

    test('Save Observation1 Again', () async {
      final observation1 = Observation(
          id: Id('obs1'),
          code: CodeableConcept(text: 'Observation #1 - Updated'));
      final saved = await resourceDao.save('newPw', observation1);

      expect(saved.id, Id('obs1'));

      expect((saved as Observation).code.text, 'Observation #1 - Updated');

      expect(saved.meta?.versionId, Id('2'));
    });

    test('Save Observation2', () async {
      final observation2 = Observation(
        id: Id('obs2'),
        code: CodeableConcept(text: 'Observation #2'),
        effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
      );
      final saved = await resourceDao.save('newPw', observation2);

      expect(saved.id, Id('obs2'));

      expect((saved as Observation).code.text, 'Observation #2');
    });

    test('Save Observation3', () async {
      final observation3 = Observation(
        id: Id('obs3'),
        code: CodeableConcept(text: 'Observation #3'),
        effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
      );
      final saved = await resourceDao.save('newPw', observation3);

      expect(saved.id, Id('obs3'));

      expect((saved as Observation).code.text, 'Observation #3');
    });
  });

  group('Password - Finding Things:', () {
    test('Find 1st Patient', () async {
      final search = await resourceDao.find('newPw',
          resourceType: R4ResourceType.Patient, id: id);
      final humanName = HumanName(family: 'Atreides', given: ['Duke']);

      expect(search.length, 1);

      expect((search[0] as Patient).name?[0], humanName);
    });

    test('Find 3rd Observation', () async {
      final search = await resourceDao.find('newPw',
          resourceType: R4ResourceType.Observation, id: Id('obs3'));

      expect(search.length, 1);

      expect(search[0].id, Id('obs3'));

      expect((search[0] as Observation).code.text, 'Observation #3');
    });

    test('Find All Observations', () async {
      final search = await resourceDao.getResourceType(
        'newPw',
        resourceTypes: [R4ResourceType.Observation],
      );

      expect(search.length, 3);

      final idList = [];
      for (final obs in search) {
        idList.add(obs.id.toString());
      }

      expect(idList.contains('obs1'), true);

      expect(idList.contains('obs2'), true);

      expect(idList.contains('obs3'), true);
    });

    test('Find All (non-historical) Resources', () async {
      final search = await resourceDao.getAll('newPw');

      expect(search.length, 5);
      final patList = search.toList();
      final orgList = search.toList();
      final obsList = search.toList();
      patList.retainWhere(
          (resource) => resource.resourceType == R4ResourceType.Patient);
      orgList.retainWhere(
          (resource) => resource.resourceType == R4ResourceType.Organization);
      obsList.retainWhere(
          (resource) => resource.resourceType == R4ResourceType.Observation);

      expect(patList.length, 1);

      expect(orgList.length, 1);

      expect(obsList.length, 3);
    });
  });

  group('Password - Deleting Things:', () {
    test('Delete 2nd Observation', () async {
      await resourceDao.delete(
          'newPw', null, R4ResourceType.Observation, Id('obs2'), null, null);

      final search = await resourceDao.getResourceType(
        'newPw',
        resourceTypes: [R4ResourceType.Observation],
      );

      expect(search.length, 2);

      final idList = [];
      for (final obs in search) {
        idList.add(obs.id.toString());
      }

      expect(idList.contains('obs1'), true);

      expect(idList.contains('obs2'), false);

      expect(idList.contains('obs3'), true);
    });

    test('Delete All Observations', () async {
      await resourceDao.deleteSingleType('newPw',
          resourceType: R4ResourceType.Observation);

      final search = await resourceDao.getAll('newPw');

      expect(search.length, 2);

      final patList = search.toList();
      final orgList = search.toList();
      patList.retainWhere(
          (resource) => resource.resourceType == R4ResourceType.Patient);
      orgList.retainWhere(
          (resource) => resource.resourceType == R4ResourceType.Organization);

      expect(patList.length, 1);

      expect(patList.length, 1);
    });

    test('Delete All Resources', () async {
      await resourceDao.deleteAllResources('newPw');

      final search = await resourceDao.getAll('newPw');

      expect(search.length, 0);

      await resourceDao.updatePw('newPw', null);
    });
  });
} 

Download Details:

Author: MayJuun

Source Code: https://github.com/MayJuun/fhir/tree/main/fhir_db

#sqflite  #dart  #flutter 

Michael  Hamill

Michael Hamill

1617331277

Workshop Alert! Deep Learning Model Deployment & Management

The Association of Data Scientists (AdaSci), the premier global professional body of data science and ML practitioners, has announced a hands-on workshop on deep learning model deployment on February 6, Saturday.

Over the last few years, the applications of deep learning models have increased exponentially, with use cases ranging from automated driving, fraud detection, healthcare, voice assistants, machine translation and text generation.

Typically, when data scientists start machine learning model development, they mostly focus on the algorithms to use, feature engineering process, and hyperparameters to make the model more accurate. However, model deployment is the most critical step in the machine learning pipeline. As a matter of fact, models can only be beneficial to a business if deployed and managed correctly. Model deployment or management is probably the most under discussed topic.

In this workshop, the attendees get to learn about ML lifecycle, from gathering data to the deployment of models. Researchers and data scientists can build a pipeline to log and deploy machine learning models. Alongside, they will be able to learn about the challenges associated with machine learning models in production and handling different toolkits to track and monitor these models once deployed.

#hands on deep learning #machine learning model deployment #machine learning models #model deployment #model deployment workshop

Mckenzie  Osiki

Mckenzie Osiki

1623906928

How To Use “Model Stacking” To Improve Machine Learning Predictions

What is Model Stacking?

Model Stacking is a way to improve model predictions by combining the outputs of multiple models and running them through another machine learning model called a meta-learner. It is a popular strategy used to win kaggle competitions, but despite their usefulness they’re rarely talked about in data science articles — which I hope to change.

Essentially a stacked model works by running the output of multiple models through a “meta-learner” (usually a linear regressor/classifier, but can be other models like decision trees). The meta-learner attempts to minimize the weakness and maximize the strengths of every individual model. The result is usually a very robust model that generalizes well on unseen data.

The architecture for a stacked model can be illustrated by the image below:

#tensorflow #neural-networks #model-stacking #how to use “model stacking” to improve machine learning predictions #model stacking #machine learning

Ananya Gupta

1601875752

AI(Artificial Intelligence): The Business Benefits of Machine Learning

Artificial intelligence has been around since a minimum of the 1950s, but it’s only within the past few years that it’s become ubiquitous. Companies we interact with every day— Amazon, Facebook, and Google—have fully embraced AI. It powers product recommendations, maps, and social media feeds.

But it’s not only the tech giants that will employ AI in their products. AI solutions are now accessible to several businesses and individuals. And it’s becoming clear that understanding and employing AI is critical for the companies of tomorrow.

What Is AI?
In the last 20 years, there are major changes in technology—notably the arrival of the mobile. But the innovation that’s on par with inventing electricity is AI.

Machine Learning
Machine learning may be a subset of AI and maybe a set of techniques that give computers the power to find out without being explicitly programmed to try to so. One example is classification, like classifying images: during a very simplistic interpretation, for instance, a computer could automatically classify pictures of apples and oranges to travel in several folders. And with more data over time, the machine will become better future scope and career oppertunity for students who want to make career in Machine Learning.

Deep Learning and Neural Networks
Deep learning may be a further subset of machine learning that permits computers to find out more complex patterns and solve more complex problems. one among the clearest applications of deep learning is in tongue processing, which powers chatbots and voice assistants like Siri. It’s the recent advent of deep learning that has particularly been driving the AI boom.

And all of those are supported neural networks, which is that the concept machines could mimic the human brain, with many layers of artificial neurons. Neural networks are powerful once they are multi-layered, with more neurons and interconnectivity. Neural networks are researched for years, but only recently has the research been pushed to the subsequent level and commercialized.

AI Business Benefits
Now that you simply have a conceptual understanding of AI and its subsets, let’s get to the guts of it: what can AI do for you and your business? We’ll explore highlights within five areas: human resources, accounting, legal, marketing and sales, and customer support.

Human Resources
Artificial intelligence poses a big opportunity in process automation. One example would be recruitment and human resources. As an example, tasks like onboarding and administration of advantages are often automated.If you want to learn deep about AI then join Artificial Intellegence class in Noida and get offer to work on live projects.

Accounting
The dutiful accountant, languishing over the bookkeeping—it’s a classic image. But now many of their services might not be needed. Many traditional bookkeeping tasks are already being performed by AI. Areas like accounts payable and receivable are taking advantage of automated data entry and categorization.

Legal
Some of the foremost fascinating advancements in AI are associated with law and legal technology. Specifically, AI can now read “legal and contractual documents to extract provisions using tongue processing.” Blue J Legal’s website touts the platform’s ability to help with employment law. The Foresight technology “analyzes data drawn from common law cases, using deep learning to get hidden patterns in previous rulings.” briefly, cases can now be analyzed much faster, insights are often drawn from across a good array of legal knowledge, and thus business decisions are often more accurate and assured.

Sales and Marketing Analytics
Analytics can now be done much more rapidly with much larger data sets because of AI. This has profound impacts on all kinds of data analysis, including business and financial decisions.

One of the quickly changing areas is marketing and sales applications. AI makes it easier to predict what a customer is probably going to shop for by learning and understanding their purchasing patterns.

Customer Support
You’ve been there. Waiting forever on a customer support line. Perhaps with a cable company or an enormous bank. Luckily, AI is close to making your life easier, if it hasn’t already.

According to the Harvard Business Review, one of the most benefits of AI is that “intelligent agents offer 24/7 customer service addressing a broad and growing array of issues from password requests to technical support questions—all within the customer’s tongue .” For customer support, a mixture of machine and deep learning can allow queries to be analyzed quicker.

Conclusion
With AI becoming ever more pervasive, having a fundamental understanding of it’s a requirement for continued business success. Whatever role you hold in your business, understanding AI may assist you to solve problems in new and innovative ways, saving time and money. Further, it’s going to assist you to build and style the products and services of the longer term.

#machine learning online training #machine learning online course #machine learning course #machine learning training in noida #artificial intelligence training in noida #artificial intelligence online training