Search in sources :

Example 6 with Source

use of com.google.cloud.securitycenter.v1.Source in project h2o-2 by h2oai.

the class GLMTest2 method testTweedieRegression.

//simple tweedie test
@Test
public void testTweedieRegression() throws InterruptedException, ExecutionException {
    Key raw = Key.make("tweedie_test_data_raw");
    Key parsed = Key.make("tweedie_test_data_parsed");
    Key modelKey = Key.make("tweedie_test");
    Frame fr = null;
    GLMModel model = null;
    try {
        // make data so that the expected coefficients is icept = col[0] = 1.0
        FVecTest.makeByteVec(raw, "x,y\n0,0\n1,0.1\n2,0.2\n3,0.3\n4,0.4\n5,0.5\n6,0.6\n7,0.7\n8,0.8\n9,0.9\n0,0\n1,0\n2,0\n3,0\n4,0\n5,0\n6,0\n7,0\n8,0\n9,0");
        fr = ParseDataset2.parse(parsed, new Key[] { raw });
        double[] powers = new double[] { 1.5, 1.1, 1.9 };
        double[] intercepts = new double[] { 3.643, 1.318, 9.154 };
        double[] xs = new double[] { -0.260, -0.0284, -0.853 };
        for (int i = 0; i < powers.length; ++i) {
            //.doInit().fork().get();
            GLM2 glm = new GLM2("GLM test of tweedie regression.", Key.make(), modelKey, new Source(fr, fr.lastVec(), false), Family.tweedie, Link.family_default, 0, true);
            glm.setTweediePower(powers[i]);
            glm.setLambda(0);
            glm.max_iter = 1000;
            glm.doInit().fork().get();
            model = DKV.get(modelKey).get();
            testHTML(model);
            HashMap<String, Double> coefs = model.coefficients();
            assertEquals(intercepts[i], coefs.get("Intercept"), 1e-3);
            assertEquals(xs[i], coefs.get("x"), 1e-3);
        }
    } finally {
        if (fr != null)
            fr.delete();
        if (model != null)
            model.delete();
    }
}
Also used : Source(hex.glm.GLM2.Source) Test(org.junit.Test)

Example 7 with Source

use of com.google.cloud.securitycenter.v1.Source in project h2o-2 by h2oai.

the class GLMTest2 method testOffset.

@Test
public void testOffset() throws InterruptedException, ExecutionException {
    Key parsed = Key.make("prostate_parsed");
    Key modelKey = Key.make("prostate_model");
    GLMModel model = null;
    File f = TestUtil.find_test_file("smalldata/glm_test/prostate_cat_replaced.csv");
    Frame fr = getFrameForFile(parsed, "smalldata/glm_test/prostate_cat_replaced.csv", new String[] { "ID" }, "CAPSULE");
    Key k = Key.make("rebalanced");
    H2O.submitTask(new RebalanceDataSet(fr, k, 64)).join();
    fr.delete();
    fr = DKV.get(k).get();
    try {
        //      R results:
        //      Call:  glm(formula = CAPSULE ~ . - ID - AGE, family = binomial, data = D,
        //        offset = D$AGE)
        //
        //      Coefficients:
        //      (Intercept)       RACER2       RACER3        DPROS        DCAPS          PSA          VOL      GLEASON
        //      -95.16718     -0.67663     -2.11848      2.31296      3.47783      0.10842     -0.08657      2.90452
        //
        //      Degrees of Freedom: 379 Total (i.e. Null);  372 Residual
        //      Null Deviance:	    2015
        //      Residual Deviance: 1516 	AIC: 1532
        // H2O differs on intercept and race, same residual deviance though
        String[] cfs1 = new String[] { /*"Intercept","RACE.R2","RACE.R3",*/
        "AGE", "DPROS", "DCAPS", "PSA", "VOL", "GLEASON" };
        double[] vals = new double[] { /*-95.16718, -0.67663, -2.11848,*/
        1, 2.31296, 3.47783, 0.10842, -0.08657, 2.90452 };
        new GLM2("GLM offset test on prostate.", Key.make(), modelKey, new GLM2.Source(fr, fr.vec("CAPSULE"), false, true, fr.vec("AGE")), Family.binomial).setRegularization(new double[] { 0 }, new double[] { 0 }).doInit().fork().get();
        model = DKV.get(modelKey).get();
        //HEX-1817
        Assert.assertTrue(model.get_params().state == Job.JobState.DONE);
        testHTML(model);
        HashMap<String, Double> coefs = model.coefficients();
        for (int i = 0; i < cfs1.length; ++i) assertEquals(vals[i], coefs.get(cfs1[i]), 1e-4);
        GLMValidation val = model.validation();
        assertEquals(2015, model.null_validation.residualDeviance(), 1e-1);
        assertEquals(1516, val.residualDeviance(), 1e-1);
        assertEquals(1532, val.aic(), 1e-1);
        fr.delete();
        // test constant offset (had issues with constant-column filtering)
        fr = getFrameForFile(parsed, "smalldata/glm_test/abcd.csv", new String[0], "D");
        new GLM2("GLM testing constant offset on a toy dataset.", Key.make(), modelKey, new GLM2.Source(fr, fr.vec("D"), false, false, fr.vec("E")), Family.gaussian).setRegularization(new double[] { 0 }, new double[] { 0 }).doInit().fork().get();
        // just test it does not blow up and the model is sane
        model = DKV.get(modelKey).get();
        // should be exactly 1
        assertEquals(model.coefficients().get("E"), 1, 0);
    } finally {
        fr.delete();
        if (model != null)
            model.delete();
    }
}
Also used : Source(hex.glm.GLM2.Source) File(java.io.File) Test(org.junit.Test)

Example 8 with Source

use of com.google.cloud.securitycenter.v1.Source in project h2o-2 by h2oai.

the class ModelSerializationTest method prepareGLMModel.

private GLMModel prepareGLMModel(String dataset, int[] ignores, int response, Family family) {
    Frame f = parseFrame(dataset);
    Key modelKey = Key.make("GLM_model_for_" + dataset);
    try {
        new GLM2("GLM test on " + dataset, Key.make(), modelKey, new Source(f, f.vec(response), true), family).doInit().fork().get();
        return DKV.get(modelKey).get();
    } finally {
        if (f != null)
            f.delete();
    }
}
Also used : Frame(water.fvec.Frame) Source(hex.glm.GLM2.Source)

Example 9 with Source

use of com.google.cloud.securitycenter.v1.Source in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateDuplicatedExtIds_noDuplicatesTest.

/**
 * VALIDATE DUPLICATED EXTERNAL IDENTIFIERS
 */
@SuppressWarnings("deprecation")
@Test
public void validateDuplicatedExtIds_noDuplicatesTest() {
    SourceEntity source1 = mock(SourceEntity.class);
    when(source1.getSourceName()).thenReturn("source name");
    when(source1.getSourceId()).thenReturn("APP-00000000000000");
    SourceOrcid sourceOrcid = new SourceOrcid();
    sourceOrcid.setPath("0000-0000-0000-0000");
    Source source2 = mock(Source.class);
    when(source2.getSourceName()).thenReturn(new SourceName("other source name"));
    when(source2.getSourceOrcid()).thenReturn(sourceOrcid);
    ExternalIDs extIds1 = getExternalIDs();
    ExternalIDs extIds2 = getExternalIDs();
    activityValidator.checkExternalIdentifiersForDuplicates(extIds1, extIds2, source2, source1);
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) SourceName(org.orcid.jaxb.model.common_v2.SourceName) SourceOrcid(org.orcid.jaxb.model.common_v2.SourceOrcid) Source(org.orcid.jaxb.model.common_v2.Source) Test(org.junit.Test)

Example 10 with Source

use of com.google.cloud.securitycenter.v1.Source in project ORCID-Source by ORCID.

the class EmailMessageSenderTest method testCreateDigest.

@Test
public void testCreateDigest() throws IOException {
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidProfile.setOrcidIdentifier(new OrcidIdentifier("0000-0000-0000-0000"));
    OrcidBio orcidBio = new OrcidBio();
    orcidProfile.setOrcidBio(orcidBio);
    PersonalDetails personalDetails = new PersonalDetails();
    orcidBio.setPersonalDetails(personalDetails);
    personalDetails.setGivenNames(new GivenNames("John"));
    personalDetails.setFamilyName(new FamilyName("Watson"));
    OrcidInternal orcidInternal = new OrcidInternal();
    Preferences preferences = new Preferences();
    orcidProfile.setOrcidInternal(orcidInternal);
    orcidInternal.setPreferences(preferences);
    preferences.setSendEmailFrequencyDays("7.0");
    List<Notification> notifications = new ArrayList<>();
    NotificationPermission notification1 = new NotificationPermission();
    notification1.setPutCode(1L);
    Items activities1 = new Items();
    notification1.setItems(activities1);
    activities1.getItems().add(createActivity(ItemType.WORK, "Work 1", "123446/67654"));
    activities1.getItems().add(createActivity(ItemType.WORK, "Work 2", "http://dx.doi.org/123446/67655"));
    notification1.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T13:39:31"));
    notification1.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/12345"));
    Source source1 = new Source();
    source1.setSourceName(new SourceName("Super Institution 1"));
    source1.setSourceClientId(new SourceClientId("APP-5555-5555-5555-5555"));
    notification1.setSource(source1);
    notifications.add(notification1);
    NotificationPermission notification2 = new NotificationPermission();
    notification2.setPutCode(2L);
    Items activities2 = new Items();
    notification2.setItems(activities2);
    activities2.getItems().add(createActivity(ItemType.EMPLOYMENT, "Employment 1 ", "12345/abc"));
    notification2.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-08-17T10:22:15"));
    notification2.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/abc"));
    Source source2 = new Source();
    source2.setSourceName(new SourceName("Super Institution 1"));
    source2.setSourceClientId(new SourceClientId("APP-5555-5555-5555-5555"));
    notification2.setSource(source2);
    notifications.add(notification2);
    NotificationPermission notification3 = new NotificationPermission();
    notification3.setPutCode(3L);
    Items activities3 = new Items();
    notification3.setItems(activities3);
    activities3.getItems().add(createActivity(ItemType.WORK, "Work 3", "12345/def"));
    activities3.getItems().add(createActivity(ItemType.WORK, "Work 4", "12345/ghi"));
    notification3.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T08:53:56"));
    notification3.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/def"));
    Source source3 = new Source();
    source3.setSourceName(new SourceName("Lovely Publisher 1"));
    notification3.setSource(source3);
    source3.setSourceClientId(new SourceClientId("APP-ABCD-ABCD-ABCD-ABCD"));
    notifications.add(notification3);
    NotificationCustom notification4 = new NotificationCustom();
    notification4.setPutCode(4L);
    notification4.setSubject("We have release a new messaging feature");
    notification4.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T08:53:56"));
    notifications.add(notification4);
    NotificationCustom notification5 = new NotificationCustom();
    notification5.setPutCode(5L);
    notification5.setSubject("The ORCID registry is now available in Orc");
    notification5.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-11T06:42:18"));
    notifications.add(notification5);
    NotificationAmended notification6 = new NotificationAmended();
    notification6.setPutCode(6L);
    notification6.setSubject("Amended by member");
    notification6.setAmendedSection(AmendedSection.FUNDING);
    notification6.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-12T18:44:36"));
    notification6.setSource(source3);
    notifications.add(notification6);
    EmailMessage emailMessage = emailMessageSender.createDigest("0000-0000-0000-0000", notifications);
    assertNotNull(emailMessage);
    String expectedBodyText = IOUtils.toString(getClass().getResourceAsStream("example_digest_email_body.txt"));
    String expectedBodyHtml = IOUtils.toString(getClass().getResourceAsStream("example_digest_email_body.html"));
    assertTrue(expectedBodyText.contains("Lovely Publisher 1 has updated recent funding on your ORCID record."));
    assertTrue(expectedBodyHtml.contains("Lovely Publisher 1 has updated recent funding on your ORCID record."));
    assertTrue(expectedBodyText.contains("Super Institution 1: Request to add items"));
    assertTrue(expectedBodyHtml.contains("Super Institution 1: Request to add items"));
    assertTrue(expectedBodyText.contains("/action"));
    assertTrue(expectedBodyHtml.contains("/action"));
    assertEquals("[ORCID] John Watson you have 6 new notifications", emailMessage.getSubject());
}
Also used : OrcidBio(org.orcid.jaxb.model.message.OrcidBio) FamilyName(org.orcid.jaxb.model.message.FamilyName) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) ArrayList(java.util.ArrayList) SourceName(org.orcid.jaxb.model.common_v2.SourceName) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) Notification(org.orcid.jaxb.model.notification_v2.Notification) Source(org.orcid.jaxb.model.common_v2.Source) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) GivenNames(org.orcid.jaxb.model.message.GivenNames) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Items(org.orcid.jaxb.model.notification.permission_v2.Items) Preferences(org.orcid.jaxb.model.message.Preferences) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)20 IOException (java.io.IOException)20 Test (org.junit.Test)17 Source (hex.glm.GLM2.Source)11 Source (org.orcid.jaxb.model.common_v2.Source)10 Instant (org.threeten.bp.Instant)6 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)5 Finding (com.google.cloud.securitycenter.v1.Finding)4 GroupFindingsRequest (com.google.cloud.securitycenter.v1.GroupFindingsRequest)4 GroupResult (com.google.cloud.securitycenter.v1.GroupResult)4 ListFindingsRequest (com.google.cloud.securitycenter.v1.ListFindingsRequest)4 ListFindingsResult (com.google.cloud.securitycenter.v1.ListFindingsResponse.ListFindingsResult)4 GroupFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse)4 ListFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse)4 Source (com.google.cloud.securitycenter.v1.Source)4 FieldMask (com.google.protobuf.FieldMask)3 SourceName (org.orcid.jaxb.model.common_v2.SourceName)3 Items (org.orcid.jaxb.model.notification.permission_v2.Items)3 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)3 Policy (com.google.iam.v1.Policy)2