Is it possible to add transformation code to pmml? - pmml

I run a linear regression code and generated a pmml. In my pmml code there are data types and regression table info. I have a pmml code like that
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<PMML version="4.2"
xmlns="http://www.dmg.org/PMML-4_2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<Application name="SAS(r)" version="9.4"/>
<Timestamp>2016-05-27 09:58:01</Timestamp>
</Header>
<DataDictionary numberOfFields="10">
<DataField name="Invoice" optype="continuous" dataType="double"/>
<DataField name="ZINT_Cylinders" optype="continuous" dataType="double"/>
<DataField name="ZINT_EngineSize" optype="continuous" dataType="double"/>
</DataDictionary>
<TransformationDictionary/>
<RegressionModel functionName="regression" targetFieldName="Invoice" normalizationMethod="none">
<MiningSchema>
<MiningField name="ZINT_Cylinders" usageType="active" optype="continuous"/>
<MiningField name="ZINT_EngineSize" usageType="active" optype="continuous"/>
</MiningSchema>
<Output>
<OutputField name="P_Invoice" displayName="Predicted: Invoice" optype="continuous" dataType="double" targetField="Invoice" feature="predictedValue"/>
</Output>
<Targets>
<Target field="Invoice" optype="continuous">
<TargetValue defaultValue="30014.700935"/>
</Target>
</Targets>
<LocalTransformations/>
<RegressionTable intercept="-4919.70174">
<NumericPredictor name="ZINT_Cylinders" coefficient="-0.007378626"/>
<NumericPredictor name="ZINT_EngineSize" coefficient="-0.147331595"/>
</RegressionTable>
</RegressionModel>
</PMML>
Before the regression step, I want to transform the my source data. For example I want to add these case when structure to my pmml. Is it possible to do this?
SELECT Invoice,
CASE
WHEN EngineSize < 2.9 THEN 20304.5142857143
WHEN EngineSize < 4.1 THEN 30378.8789808917
WHEN EngineSize >= 4.1 THEN 47119.9791666667
ELSE 30014.7009345794
END AS ZINT_EngineSize,
CASE
WHEN Cylinders < 4.5 THEN 18349.4452554745
WHEN Cylinders < 7 THEN 29472.3819095477
WHEN Cylinders >= 7 THEN 48558.847826087
ELSE 30014.7009345794
END AS ZINT_Cylinders
FROM MYSOURCE.MYTABLE;

You can use the Discretize transformation for the job:
<DerivedField name="ZINT_EngineSize" dataType="double" optype="continuous">
<Discretize field="EngineSize">
<DiscretizeBin binValue="20304.5142857143">
<!-- EngineSize < 2.9 -->
<Interval closure="openOpen" rightMargin="2.9"/>
</DiscretizeBin>
<DiscretizeBin binValue="30378.8789808917">
<!-- EngineSize >= 2.9 && EngineSize < 4.1 -->
<Interval closure="closedOpen" leftMargin="2.9" rightMargin="4.1"/>
</DiscretizeBin>
<DiscretizeBin binValue="47119.9791666667">
<!-- EngineSize >= 4.1 -->
<Interval closure="closedOpen" leftMargin="4.1"/>
</DiscretizeBin>
</Discretize>
</DerivedField>
You could build a parser for SAS script, and automate the generation and embedding of Discretize elements using the JPMML-Model library.

Related

URDF model keeps disappearing whenever I add intertial properties to a link? How can I resolve this issue?

I am trying to simulate a simple pendulum using pydrake and am having a couple of issues creating the urdf file to creat the model for the pendulum. I have no background knowledge on urdf or drake and am open to any suggestions to resolve this issue.
This is the code I have so far:
import os
from tempfile import mkdtemp
from pydrake.all import (
AddMultibodyPlantSceneGraph,
DiagramBuilder,
Meshcat,
MeshcatVisualizerCpp,
Parser,
Simulator,
)
from manipulation.meshcat_cpp_utils import (
StartMeshcat, MeshcatJointSlidersThatPublish)
# Start the visualizer.
meshcat = StartMeshcat()
tmp_dir = mkdtemp()
model_file = os.path.join(tmp_dir, "test_model.urdf")
model_text = f"""\
<?xml version="1.0"?>
<robot name="materials">
<material name="blue">
<color rgba="0 0 0.8 1"/>
</material>
<material name="white">
<color rgba="1 1 1 1"/>
</material>
<material name="green">
<color rgba="0.0 0.8 0.0 1.0"/>
</material>
<link name="base">
<visual>
<geometry>
<box size="0.5 0.5 0.1"/>
</geometry>
</visual>
<inertial>
<mass value="1"/>
</inertial>
</link>
<joint name="world_2_base" type="fixed">
<parent link="world"/>
<child link="base"/>
<origin xyz="0 0 0.5"/>
</joint>
<link name="arm">
<visual>
<geometry>
<cylinder length="0.5" radius="0.01"/>
</geometry>
<material name="blue"/>
</visual>
</link>
<joint name="base" type="revolute">
<parent link="base"/>
<child link="arm"/>
<axis xyz="1 0 0"/>
<origin xyz="0 0 -0.3"/>
</joint>
<link name="ball">
<visual>
<geometry>
<sphere radius="0.1"/>
</geometry>
<material name="green"/>
</visual>
</link>
<joint name="base2" type="fixed">
<parent link="arm"/>
<child link="ball"/>
<origin xyz="0 0 -0.35"/>
</joint>
</robot>
"""
# Write temporary file.
with open(model_file, "w") as f:
f.write(model_text)
builder = DiagramBuilder()
plant, scene_graph = AddMultibodyPlantSceneGraph(builder, time_step=0.0)
# Add pendulum model.
model = Parser(plant, scene_graph).AddModelFromFile(model_file)
# - Weld base at origin.
base_link = plant.GetBodyByName("base", model)
#plant.WeldFrames(plant.world_frame(), base_link.body_frame())
plant.Finalize()
visualizer = MeshcatVisualizerCpp.AddToBuilder(builder, scene_graph, meshcat)
diagram = builder.Build()
simulator = Simulator(diagram)
simulator.set_target_realtime_rate(1.0)
simulator.AdvanceTo(5.0)
This code gives me a blanck meshcat screen. But when I remove the inertia tags in the base link I can see a model of the pendulum. Please let me know what I am doing wrong. Also if you can reccomend some resources to learn about urdf and drake that would be really helpful.
Thank you very much.
I believe that the problem is that you have no mass in the arm, so when you go to simulate it, the simulation is ill-defined (probably you get NaNs in the state variables).
If you want to check just the visualization, I'd recommend doing
context = diagram.CreateDefaultContext()
diagram.Publish(context)
instead of the simulator step.
I have started working on a proper tutorial for precisely this. It's very much a draft right now, but in case it helps you can find it here. I intend for this to be one of the real Drake tutorials soon.

Pressure topic is not published when add barometric pressure Sensor with geometry_msgs/PointStamped

To use http://wiki.ros.org/hector_pose_estimation?distro=noetic hector_pose_estimation package i need to fuse IMU and barometric pressure Sensor with geometry_msgs/PointStamped So I add such barometric pressure Sensor with geometry_msgs/PointStamped with gazebo_ros_plugins.
Here is the urdf.xacro of the barometric pressure Sensor
<?xml version="1.0"?>
<!-- Copyright (c) 2016 The UUV Simulator Authors.
All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:macro name="no_collision">
<collision>
<geometry>
<cylinder length="${0.000001}" radius="${0.000001}" />
</geometry>
<origin xyz="0 0 0" rpy="0 ${0.5*pi} 0"/>
</collision>
</xacro:macro>
<xacro:macro name="default_pressure_macro" params="namespace parent_link *origin">
<xacro:pressure_plugin_macro
namespace="${namespace}"
suffix=""
parent_link="${parent_link}"
topic="pressure"
mass="0.015"
update_rate="10"
range="30000"
noise_sigma="3.0"
noise_amplitude="0.0"
estimateDepth="false"
standardPressure="101.325"
kPaPerM="9.80638">
<inertia ixx="0.00001" ixy="0.0" ixz="0.0" iyy="0.00001" iyz="0.0" izz="0.00001" />
<xacro:insert_block name="origin" />>
</xacro:pressure_plugin_macro>
</xacro:macro>
<xacro:macro name="default_pressure" params="namespace parent_link *origin">
<xacro:pressure_plugin_macro
namespace="${namespace}"
suffix=""
parent_link="${parent_link}"
topic="pressure"
mass="0.015"
update_rate="10"
range="30000"
noise_sigma="3.0"
noise_amplitude="0.0"
estimateDepth="false"
standardPressure="101.325"
kPaPerM="9.80638">
<inertia ixx="0.00001" ixy="0.0" ixz="0.0" iyy="0.00001" iyz="0.0" izz="0.00001" />
<xacro:insert_block name="origin" />
</xacro:pressure_plugin_macro>
</xacro:macro>
<xacro:macro name="pressure_plugin_macro"
params="namespace suffix parent_link topic mass update_rate
range noise_sigma noise_amplitude estimateDepth standardPressure kPaPerM
*inertia *origin">
<link name="${namespace}/pressure${suffix}_link">
<inertial>
<xacro:insert_block name="inertia" />
<mass value="${mass}" /> <!-- [kg] -->
<origin xyz="0 0 0" rpy="0 0 0" />
</inertial>
<visual>
<geometry>
<mesh filename="file://$(find uuv_sensor_ros_plugins)/meshes/pressure.dae" scale="1 1 1"/>
</geometry>
</visual>
<xacro:no_collision/>
</link>
<joint name="${namespace}/pressure${suffix}_joint" type="revolute">
<xacro:insert_block name="origin" />
<parent link="${parent_link}" />
<child link="${namespace}/pressure${suffix}_link" />
<limit upper="0" lower="0" effort="0" velocity="0" />
<axis xyz="1 0 0"/>
</joint>
<gazebo>
<plugin filename="librotors_gazebo_pressure_plugin.so" name="rotors_gazebo_pressure_sensor${suffix}_plugin">
<robot_namespace>${namespace}</robot_namespace> <!-- (string, required): ros namespace in which the messages are published -->
<linkName>${namespace}/pressure${suffix}_link</linkName> <!-- (string, required): name of the body which holds the IMU sensor -->
<sensor_topic>${topic}</sensor_topic> <!-- (string): name of the sensor output topic and prefix of service names (defaults to imu) -->
<update_rate>${update_rate}</update_rate> <!-- Update period of accelerometer and gyroscope [s] -->
<saturation>${range}</saturation> <!-- measurement range [kPa] -->
<noise_sigma>${noise_sigma}</noise_sigma> <!-- measurement stddev [kPa] -->
<noise_amplitude>${noise_amplitude}</noise_amplitude>
<estimate_depth_on>${estimateDepth}</estimate_depth_on> <!-- infer depth? -->
<standard_pressure>${standardPressure}</standard_pressure> <!-- pressure at sea level (depth 0 m) [kPa] -->
<kPa_per_meter>${kPaPerM}</kPa_per_meter> <!-- increase in pressure [kPa] per [m] in increased depth -->
<enable_gazebo_messages>false</enable_gazebo_messages>
</plugin>
</gazebo>
</xacro:macro>
</robot>
I can compile and run Gazebo and got this line in blue [Dbg] [gazebo_pressure_plugin.cpp:39] _model = rexrov2
When run rostopic list the pressure topic is not published.The plugin file librotors_gazebo_pressure_plugin is there.
Any help?

How to properly add a torsional_spring element to a RigidBodyTree in Drake

I am using the Drake simulator, and attempting to add joint stiffness to the Acrobot demo found in the underactuated robotics repo, and so far have been unable to successfully integrate such stiffness into the simulation.
I am running the script torque_slider_demo.py, which references the URDF file acrobot.urdf. I modified this URDF to include a torsional spring entry as follows:
<torsional_spring stiffness = "100000000" rest_angle = ".75">
<joint name = "shoulder"/>
</torsional_spring>
This element is added after defining joints (Full XML shown below), and I increased damping in both joints to more quickly see steady-state behavior.
<?xml version="1.0"?>
<robot xmlns="http://drake.mit.edu"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="Acrobot">
<link name="base_link">
<visual>
<geometry>
<box size="0.2 0.2 0.2" />
</geometry>
<material name="green">
<color rgba="0 1 0 1" />
</material>
</visual>
</link>
<link name="upper_link">
<inertial>
<origin xyz="0 0 -.5" rpy="0 0 0" />
<mass value="1" />
<inertia ixx="1" ixy="0" ixz="0" iyy="0.083" iyz="0" izz="1" />
</inertial>
<visual>
<origin xyz="0 0 -0.5" rpy="0 0 0" />
<geometry>
<cylinder length="1.1" radius="0.05" />
</geometry>
<material name="red">
<color rgba="1 0 0 1" />
</material>
</visual>
</link>
<link name="lower_link">
<inertial>
<origin xyz="0 0 -1" rpy="0 0 0" />
<mass value="1" />
<inertia ixx="1" ixy="0" ixz="0" iyy="0.33" iyz="0" izz="1" />
</inertial>
<visual>
<origin xyz="0 0 -1" rpy="0 0 0" />
<geometry>
<cylinder length="2.1" radius=".05" />
</geometry>
<material name="blue">
<color rgba="0 0 1 1" />
</material>
</visual>
</link>
<joint name="shoulder" type="continuous">
<parent link="base_link" />
<child link="upper_link" />
<origin xyz="0 0.15 0" />
<axis xyz="0 1 0" />
<dynamics damping="1" />
</joint>
<joint name="elbow" type="continuous">
<parent link="upper_link" />
<child link="lower_link" />
<origin xyz="0 0.1 -1" />
<axis xyz="0 1 0" />
<dynamics damping="1" />
</joint>
<torsional_spring stiffness = "100000000" rest_angle = ".75">
<joint name = "shoulder"/>
</torsional_spring>
<transmission type="SimpleTransmission" name="elbow_trans">
<actuator name="elbow" />
<joint name="elbow" />
<mechanicalReduction>1</mechanicalReduction>
</transmission>
</robot>
With this absurdly high stiffness value, I would expect for the arm to stabilize around the resting angle of the spring and exhibit an obvious pull towards the resting angle, however I do not see these effects in the visualization produced by the script.
Am I improperly defining the torsional spring in the URDF? Do I need to do some other setup to tell the simulator to consider joint stiffness?
It looks like we have support for torsional springs, but don't actually load them from URDF (nor expose the interface in python):
https://github.com/RobotLocomotion/drake/blob/master/attic/multibody/test/rigid_body_tree/rigid_body_tree_spring_test.cc
It would not be hard to add, and we'd welcome the contribution if you want to add the few lines to the parser. The drake developers are focused on multibodyplant now (which will replace rigidbodyplant).

Subtracting n hours from a DateTime in XSLT

I have a node in my file XSLT, i want subtracting n hours.
<xsl:element name="DocDate">
<xsl:variable name="Date" select="'2013-11-21T11:41:25'"/>
<xsl:variable name="Date_sub" select="substring($Date,12,19)" /> //Here i bring the hour (11:41:25)
</xsl:element>
But now i want subtracting n hours for example subtract two hours. I want some like this:
Hour = (11:41:25) - (02:00:00) = (09:41:25). Some suggestions? Thanks
Sorry, i´m using XSL 1.0.
You can use "date add" function/template from EXSLT (http://exslt.org/date/functions/add/date.add.html).
XSL Template: http://exslt.org/date/functions/add/date.add.template.xsl
Example to add 2h to current date:
<xsl:stylesheet version="1.0"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date"
...>
<xsl:import href="date.add.template.xsl" />
...
<xsl:call-template name="date:add">
<xsl:with-param name="date-time"><xsl:value-of select="current-date()" /></xsl:with-param>
<xsl:with-param name="duration">PT2H</xsl:with-param>
</xsl:call-template>
</xsl:stylesheet>

XML string with HTML Tags

hi my question is pretty simple that how to parse XML that contain HTML tags like id, br, code, href, Anchor and many more. now i m using XMLReader to get dictonary but its fails to convert it due to tag. i m sure because i test it with simple XML without html tag.
here is sample XML
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="http://www.accessdata.fda.gov/spl/stylesheet/spl.xsl" type="text/xsl"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 http://www.accessdata.fda.gov/spl/schema/spl.xsd">
<id root="fdd1fa5e-9dbf-4951-a8e9-33d06e05bdba"/>
<code code="34391-3" codeSystem="2.16.840.1.113883.6.1" displayName="HUMAN PRESCRIPTION DRUG LABEL"/>
<title>WELLBUTRIN XL<sup>®</sup>
<br/>(bupropion hydrochloride extended-release tablets)</title>
<effectiveTime value="20101201"/>
<setId root="fdd1fa5e-9dbf-4951-a8e9-33d06e05bdba"/>
<versionNumber value="1"/>
<author>
<time/>
<assignedEntity>
<representedOrganization>
<id extension="118802834" root="1.3.6.1.4.1.519.1"/>
<name>Rebel Distributors Corp</name>
<assignedEntity>
<assignedOrganization>
<assignedEntity>
<assignedOrganization>
<id extension="118802834" root="1.3.6.1.4.1.519.1"/>
<name>Rebel Distributors Corp</name>
</assignedOrganization>
<performance>
<actDefinition>
<code code="C73607" codeSystem="2.16.840.1.113883.3.26.1.1" displayName="RELABEL"/>
</actDefinition>
</performance>
<performance>
<actDefinition>
<code code="C73606" codeSystem="2.16.840.1.113883.3.26.1.1" displayName="REPACK"/>
</actDefinition>
</performance>
</assignedEntity>
</assignedOrganization>
</assignedEntity>
</representedOrganization>
</assignedEntity>
</author>
<component>
<section ID="i4i_pharmacokinetics_id_64f18136-4148-40b6-bdc1-5a836f89badf">
<id root="b72d6d1f-ba84-4360-b6d2-356e2659d444"/>
<code codeSystem="2.16.840.1.113883.6.1" code="43682-4" displayName="PHARMACOKINETICS SECTION"/>
<text>
<paragraph>
<content styleCode="bold">Pharmacokinetics: </content>Bupropion is a racemic mixture. The pharmacologic activity and pharmacokinetics of the individual enantiomers have not been studied. The mean elimination half-life (±SD) of bupropion after chronic dosing is 21 (±9) hours, and steady-state plasma concentrations of bupropion are reached within 8 days.</paragraph>
<paragraph>In a study comparing 14-day dosing with WELLBUTRIN XL 300 mg once daily to the immediate-release formulation of bupropion at 100 mg 3 times daily, equivalence was demonstrated for peak plasma concentration and area under the curve for bupropion and the 3 metabolites (hydroxybupropion, threohydrobupropion, and erythrohydrobupropion). Additionally, in a study comparing 14-day dosing with WELLBUTRIN XL 300 mg once daily to the sustained-release formulation of bupropion at 150 mg 2 times daily, equivalence was demonstrated for peak plasma concentration and area under the curve for bupropion and the 3 metabolites.</paragraph>
</text>
<effectiveTime value="20100602"/>
<component>
<section ID="i4i_section_id_6d40273a-9091-4892-8274-c5d63bfd5e3d">
<id root="49620c24-b19c-4e05-8d56-cf59a423a74a"/>
<code codeSystem="2.16.840.1.113883.6.1" code="42229-5" displayName="SPL UNCLASSIFIED SECTION"/>
<text>
<paragraph>
<content styleCode="bold">
<content styleCode="italics">Absorption: </content>
</content>Following oral administration of WELLBUTRIN XL to healthy volunteers, time to peak plasma concentrations for bupropion was approximately 5 hours and food did not affect the C<sub>max</sub> or AUC of bupropion. </paragraph>
</text>
<effectiveTime value="20100602"/>
</section>
</component>
<component>
Please help me out of this thanks in advance....